I get this warning in my error logs and wanted to know how to correct this issues in my code.
Warning: PHP Notice: Undefined property: stdClass::$records in script
if(isset($response->records))
print "we've got records!";
If you want to use property_exists, you'll need to get the name of the class with get_class()
In this case it would be :
if( property_exists( get_class($response), 'records' ) ){
$role_arr = getRole($response->records);
}
else
{
...
}
Depending on whether you're looking for a member or method, you can use either of these two functions to see if a member/method exists in a particular object:
http://php.net/manual/en/function.method-exists.php
http://php.net/manual/en/function.property-exists.php
More generally if you want all of them:
http://php.net/manual/en/function.get-object-vars.php
The response itself seems to have the size of the records. You can use that to check if records exist. Something like:
if($response->size > 0){
$role_arr = getRole($response->records);
}
If think this will work:
if(sizeof($response->records)>0)
$role_arr = getRole($response->records);
newly defined proprties included too.
In this case, I would use:
if (!empty($response->records)) {
// do something
}
You won't get any ugly notices if the property doesn't exist, and you'll know you've actually got some records to work with, ie. $response->records is not an empty array, NULL, FALSE, or any other empty values.