Jump to content
Killersites Forums

Fatal Error class not found issue


mopardude
 Share

Recommended Posts

Ok here is the situation I have a basic class called email

 

class Email{

public $email_subject;
public $email_to_address;
public $email_from_address;
public $email_message;

public function send_email(){
	$this->mail($this->email_to_address, $this->email_subject, $this->email_message, $this->email_from_address);
}
}

 

Works perfect by itself. Than when I try to extend it I get en error in the first line.

 

class its_Email extends Email{	

public $email_from_address = "From: Mopardude's Site<myemail@somedomain.com>";	

public function __construct(){

	$this->email_from_address = $email_from_address;

}

}

 

Both classes are in the same class directory which are auto included by a script at startup. At first I thought the extend class was being instancitiated before email was included, but really that is not possible if both classes are included before the call to them is ever made right? The funny thing is I have a similar class that is extended the same way and that work perfectly. Any ideas what I did wrong here?

Link to comment
Share on other sites

I've tested this like so:

 

-- created a new .php file with the first Email class

-- created a new .php file with the second its_Email class

-- created a third .php file that includes the above two files and creates a new its_Email object.

 

This works fine, as far as I can tell. I don't get any "class not found" errors. I do get an error in this line:

 

$this->email_from_address = $email_from_address;

 

I'm not sure what you are trying to do here, but it doesn't make much sense to me. You already set $this->email_from_address in your "public $email_from_address..." line. $this->email_from_address and $email_from_address are different variables ($this->email... is accessible to all functions within the object, but $email... only exists within the constructor), and you never set the $email_from_address variable. That line currently gives me this notice:

 

Notice: Undefined variable: email_from_address in /Applications/MAMP/htdocs/Experiments/email2.php on line 9
its_Email Object ( [email_from_address] => [email_subject] => [email_to_address] => [email_message] => )

Are you sure that both Email and its_Email are being included properly? That's the only thing I can think of.

Link to comment
Share on other sites

 

I'm not sure what you are trying to do here, but it doesn't make much sense to me. You already set $this->email_from_address in your "public $email_from_address..." line. $this->email_from_address and $email_from_address are different variables ($this->email... is accessible to all functions within the object, but $email... only exists within the constructor), and you never set the $email_from_address variable. That line currently gives me this notice:

 

Are you sure that both Email and its_Email are being included properly? That's the only thing I can think of.

 

Yea that code looks stupid because I was experimenting with a few ideas than I gutted it down from the original to troubleshoot my problem.

 

Since your thinking was the same as mine about it being included properly or not got me thinking. So I went back and looked at the problem in a different way and I discovered I am calling that its_email class from inside another class. Could this be my problem?

 

This is a slimmed down version of the method from the class that is calling its_Email.

 

public function somefunction(){	

	$new_email = new its_Email();
	$new_email->email_subject = $this->email_subject;
	$new_email->email_to_address = $this->email_address;
	$new_email->email_message = "msg to be sent";
	$new_email->send_email();	

}

Link to comment
Share on other sites

public function somefunction(){	

	$new_email = new its_Email();
	$new_email->email_subject = $this->email_subject;
	$new_email->email_to_address = $this->email_address;
	$new_email->email_message = "msg to be sent";
	$new_email->send_email();	

}

 

I moved this code out of the class it was in and it made no difference. I also tested it only using the 3 files like you and it didn't error out anymore. I have a script that scans the class dir and auto includes all the class files. So if that wasn't working correctly I would have way more than 1 class that wouldn't be working. When I manually add the includes for both classes it tells me I am redeclaring them. For what that its_Email class does at this point I can do what needs to be done other ways. File this problem away in the back of my head and come back to it when I better understand extending classes.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...