I'm having a problem creating webservices through nuSOAP (although i believe my problem has nothing to do with it)
What i'm trying to do:
function loadActiveItems() {
$list = Item::loadActive();
$ret = array();
foreach ($list as $val){
//two tests to check if i really have an object and if the toDTO method is callable
echo var_dump($val);
echo is_callable(array($val, 'toDTO'));
array_push($ret, $val->toDTO());
}
unset($val);
return $ret;
}
I'm getting the following error:
Call to a member function toDTO() on a non-object
and both var_dump($val)
and is_callable
are returning the expected (the object and true, respectively) from what i've been seeing online, it appears i have a out of scope problem... but for some reason i don't seem to get my head around it :P
Thanks in advance
EDIT: well just check that apparently i don't understand is_callable either because i always get 1 as the result... EDIT2: i'm using php-activerecord if that helps in any way
Okay so i figured out the problem... thanks for all the help! I was calling toDTO of another object inside toDTO... problem was that object could be a null! So a simple if(object==null) solved the problem!
Thanks again!
toDTO()
may be undefined in your class Item
.
Another reason may be that the method isn't public or as @Grep said` static.
This error never happens on an object that defines the method but it is static or protected/private:
Call to a member function toDTO() on a non-object
That error only happens if $val
is not an object. Usually a NULL, FALSE or other scalar.
It's usually a FALSE when the object came for a db_fetch()
function but the fetch or the query before it failed.
It's usually a NULL when you have an array that may have NULLs in it.
var_dump($list)
and see what's in there and if there are any NULLs. Also change your foreach to have a $key and var_dump($key)
as well to see which key is dumped last before the error is issued.