Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I am working on code I didn't create and am getting the error: "Fatal error: Call to undefined method stdClass::update() in" when trying to activate the Account::update() method. I believe I should be dealing with an Account object, as in other places the same function used to generate the Account object generates an Account object. I'm not sure what stdClass is, and why the same function could alternatively generate an Account object and a stdClass object. When I print the object out, indeed one is stdClass with only one key-value data pair (accountStatus), and one is the regular Account object with many key-value data pairs. I'll include the code below, but I think the first thing that would help me is understanding when/why a stdClass would be generated instead of an object.
Thanks!
Allison
Both these functions seem to produce a stdClass object unless the Account Status=Active (which is the default), in which case it creates an Account object:Code: Select all
// Create Account Object
$userData["Account"] = Account::getByID($userData["User"]->account_ID, 'Any');
// Create Account Object
$userData["Account"] = Account::getByID($u->account_ID);Code: Select all
// Create Account Object
$userData["Account"] = Account::getByID($userData["User"]->account_ID, 'Inactive');
/**
* @return object
*/
static function getByID($ID, $AccountStatus='Active')
{
$data=array();
foreach(Account::getList($AccountStatus) as $d)
{
if(($d->ID == $ID) AND (($AccountStatus == 'Any') OR ($d->accountStatus == $AccountStatus)))
{
return $d;
}
}
return FALSE;
}
/**
* @return array
*/
static function getList($accountStatus='Active')
{
//If we're using the cache, and it's already filled
if(USE_CACHE
AND ($cache = Cache::getInstance())
AND ($data = $cache->fetch('account')))
{
//no action necessary because we successfully pulled
//the data from cache
}
else
{
//Pull entire table into memory.
$Query = "SELECT " .
"ID," .
"sponsor_ID, " .
"Name," .
"StreetAddress1," .
"StreetAddress2," .
"City," .
"State," .
"Zip," .
"Phone," .
"Fax," .
"Email," .
"Website," .
"accountStatus," .
"UNIX_TIMESTAMP(DateCreated) AS DateCreated," .
"UNIX_TIMESTAMP(DateLastUpdated) AS DateLastUpdated " .
"FROM account ";
if(!($DatabaseResult = mysql_query($Query)))
{
addToLog("Account::getList() failed", LOG_EMERGENCY, __FILE__, __LINE__);
return(FALSE);
}
$data = array();
while($Row = mysql_fetch_object($DatabaseResult))
{
$data[] = Account::getInstanceFromArray($Row);
}
if(USE_CACHE)
{
$cache = Cache::getInstance();
$cache->store('account', $data);
}
}
$list = array();
foreach($data as $d)
{
if($d->accountStatus == $accountStatus)
{
$list[] = $d;
}
}
return($list);
}Weirdan | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]