logo       

PHP Fatal error: Call to a member function on a non-object...: msg#00407

php.pear.general

Subject: PHP Fatal error: Call to a member function on a non-object...

Hi,

If I've got a class with a method that uses PEAR's Mail class, why wouldn't this work ???

// mail_test.php

require_once("Mail.php");

class users { // open the class definition

/**
* PEAR mail object
*
* @var object
* @access private
*/
var $_oMail;

// CONSTRUCTOR ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

/**
* class constructor
*
* @param integer user id [optional]
* @access public
*/
function users(') {

// implement pear mail object
$this->_oMail =& Mail::factory("mail");

if (PEAR::isError($this->_oMail)) {

catchExc($this->_oMail->getMessage());
}

}

**
* send email notification
*
* @param string $sBody email body
* @return boolean
* @access private
*/
function _notifyUser($sBody) {

// assign mail properties
$aUser = $this->getUser();
$aHeaders["To"] = $sRecipients = $aUser["Email"];
$aHeaders["From"] = ENTITY." Admin <".EMAIL.">";
$aHeaders["Subject"] = ENTITY." System Account Notification";
$aHeaders["Priority"] = "3";

// try to send mail
if (PEAR::isError($mailTmp = $this->_oMail->send($sRecipients, $aHeaders, $sBody))) {
catchExc($mailTmp->getMessage());
return false;
}

return true;
}
}

The code above has been stripped down, but I always get this error when anything tries to call the notifyUser() method:

PHP Fatal error: Call to a member function on a non-object in /Library/WebServer/Documents/mail_test.php

If I remove the actual line that sends the email, then everything works fine, but, obviously, the email never gets sent!

why doesn't $this->_oMail appear to be part of the class ???? Is that the problem ??

Thanks in advance,

Jon


jon bennett | jon@xxxxxxxx
new media designer / developer
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

J b e n . n e t

91 Gloucester Rd, Trowbridge, Wilts, BA14 0AD
t: +44 (0) 1225 341039 w: http://www.jben.net/

--
PEAR General Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise