Cannot instantiate non-existent class issue


#1

I am getting the following error:

Fatal error: Cannot instantiate non-existent class: is_login_class in /home/dir/public_html/editalbum/edit/index.php on line 3

on the following code:
[php]

<?php include("complete_inc_URL?user_name=$user_name"); $incl = new is_login_class(); if ($incl->is_login($user_name) == false || $user_name == 'NULL') { Header("Location: complete_new_URL"); } ... ?>

[/php]

I have checked various tutorials I have including php.net and searched on google and could not fine a resolution for this issue.

Thank you for all your help


#2

OOP isn’t my strong point but he new keyword is trying to create a new instance of is_login_class. Now unless your include statement has a constructor method of this class there is no way for it to be created.


#3

What if the constructor does not have any contents

ie [php]

<?php ... function is_login_class() {} ... ?>

[/php]

I am not using the constructor. I have written a different function to meet my needs. Does php require the constructor to be used (unlike Java and C/C++)?

I did add that code to my include file and nothing happened.

Thanks


#4

don’t quote me on this but I beleive that prior to php5 you needed to have something passed, and for PHP5 you use the __construct. I honest don’t know… maybe someone else can tell you. I don’t normally program in OOP.


#5

You need to define a class first before you can use your constructor. The constructor and the function have the same name.

So, you have something like this:

[php]
class is_login_class
{
function is_login_class()
{}
}
[/php]

Hope that helps.


#6

I have that constructor but I am not using it here

I am using the function is_login($user_name) as you can see from my code above. How do I get this function to work correctly?

Thank you


#7

If all your trying to do is retreive some data from the URL why not use the $_GET array? As for the is_login class… sorry but OOP is out of my range of knowledge.


#8

That is not all I am trying to do. I have a function in this class I am trying to run. Can anybody help me with this post?


#9

So, are we understanding this correctly? You have a function called:

is_login();

Which you are then trying to get to work by doing the following:

is_login($user_name);

Your problem with that is you haven`t declared a parameter for the function. You need to do something like this:

[php]
class is_login_class
{

              var $user_name;

              function is_login($parameter)
              {
         
                $parameter = $this->user_name;          
     
              }

}
[/php]

Then add whatever else code you need.


#10

That is what I am doing

I have a class is_login_class.php with a is_login() function inside of it.

[php]

<?php class is_login_class { var $user_name; function is_login($name) { $name = $this->user_name; ... ?>

[/php]

Now in a different *.php program I am making an instance of this class and I call the is_login($name) function.

[php]

<?php include("_some_full_URL_"); $incl = new is_login_class(); if ($incl->is_login($user_name) == false ... ?>

[/php]

The error it gives me is

Fatal error: Cannot instantiate non-existent class: is_login_class in /home/dir/public_html/editalbum/edit/index.php on line 3

I hope this helps. Thank you for your help


#11

Are you including the *.php file that holds the class on the page that you are creating a new instance of it?

[php]
@include (‘is_login_class.php’);
[/php]


#12

I had a

[php]include(“the_URL”);[/php]

I did not have the ‘@’ attached to it. I went ahead and did so though but nothing changed. Still same error. Also all the references I have had include() not @include(). Which is right?

Thanks


#13

The @ symbol simply masks errors, and is not necessary. I`m wondering if your problem is because you have used the word ‘class’ in your variable name? ‘class’ is a reserved keyword and should not really be used when you name variables.

Try renaming your is_login_class() to something else.


#14

Isn’t this how it is supposed to be done in php5?

[php]
class is_login_class
{
protected $user_name;

function __construct ($param)

{
$this->user_name = $param;
}

function is_login() 

{
$name = $this->user_name;

}
}
[/php]


#15

carella

I changed the name to is_login_cc.php. Same error