First let me say wonderful job. Always loved this project and the new version is outstanding.
I miss read your directions in the manual and didn't make a Swift_MailTransport::newInstance to go with the Swift_Mailer::newInstance. What happened was it gave me an error saying that IsStarted could not be found. After a few wtf minutes I figured it out. But that brings up my suggestion, that perhaps you should validate the instances that get passed in when making a new instance or at least check to make sure that something is there. Because the error you get when you don't doesn't make sense in the contents of what you are doing.
Anyways nice work.
Error checking the objects on instance creating
Moderators: Chris Corbyn, General Moderators
- Technocrat
- Forum Contributor
- Posts: 127
- Joined: Thu Oct 20, 2005 7:01 pm
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Error checking the objects on instance creating
I'm not 100% I understand what you mean. Can you post some code that revealed an error? Swift Mailer does type-hint on its parameters so you shouldbnn't have been able to pass the wrong instance to say "new Swift_Mailer( $badInstance ).
Thanks for the compliments on the work
Thanks for the compliments on the work
- Technocrat
- Forum Contributor
- Posts: 127
- Joined: Thu Oct 20, 2005 7:01 pm
Re: Error checking the objects on instance creating
Notice I made a new Mailer instance without a transport.
So it makes it all the way to $mailer->send($message); without an error. Then that errors saying the the line:
Could not run because isStarted isn't part of the object. Well obviously because I stupidly didn't make a transport object
So the problem is that (at least for me) when newInstance runs it assumes that the passed in transport object is valid and just assigns it. When it probably should be validated a bit more before it gets to that point to keep people like me from hurting ourselves.
Code: Select all
private function _send() {
//Swiftmailer
include_once(_INCLUDES.'swiftmailer/swift_required.php');
$mailer = Swift_Mailer::newInstance();
$message = Swift_Message::newInstance();
$message->setSubject($this->subject);
$message->setBody($this->message, 'text/html');
$message->setFrom(array($this->from => $this->from_name));
$message->setTo($this->to);
$mailer->send($message);
}Code: Select all
if (!$this->_transport->isStarted())So the problem is that (at least for me) when newInstance runs it assumes that the passed in transport object is valid and just assigns it. When it probably should be validated a bit more before it gets to that point to keep people like me from hurting ourselves.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Error checking the objects on instance creating
That's interesting, and you never got an error?
PHP should be fatal erroring on that. Beyond Swift Mailer's control really unless I follow every type-hinted method with an instanceof check, which sort of seems redundant.
Do you have full error reporting on?
Code: Select all
/**
* Create a new Mailer instance.
*
* @param Swift_Transport $transport
* @return Swift_Mailer
*/
public static function newInstance(Swift_Transport $transport)
{
return new self($transport);
}Do you have full error reporting on?
- Technocrat
- Forum Contributor
- Posts: 127
- Joined: Thu Oct 20, 2005 7:01 pm
Re: Error checking the objects on instance creating
I figured it out finally. I had the function being used with set_error_handler not returning false, thus it was hiding the error. Sorry about that.