
November 24th, 2003, 01:29 PM
|
|
Contributing User
|
|
Join Date: Apr 2003
Posts: 51
Time spent in forums: 19 m 41 sec
Reputation Power: 6
|
|
|
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 ???
PHP Code:
// 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;
}
/**
* deactivate a user record
*
* @return boolean
* @access public
*/
function deactivateUser() {
$sql = "UPDATE ".PREFIX."_admin_users SET
status=0
WHERE
admin_user_id=".$this->_iUserId;
if (DB::isError($rsTmp = $this->_oConn->query($sql))) {
catchExc($rsTmp->getMessage());
return false;
}
// build user email
$sBody = "Your ".ENTITY." account has been deactivated.";
return $this->_notifyUser($sBody);
}
}
The notifyUser method is called from within the deleteUser method (and others)
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
|