Monday 1 September 2008

PHP: Cannot use object of type stdClass

When handling object, you have to remember to retieve LIKE an object, NOT an like array style.

Example Object retrieval:
$varName->someThingToGet


PHP Example
Make sure you just use

echo $response->TransactionID;
NOT
echo $response['TransactionID'];

Zend Framework
[ ZEND_DB Example ]
When handling You must remember to set the db adaptor to fetch object, so anything returned will fetched as a proper object.

$this->db->setFetchMode(Zend_Db::FETCH_OBJ);
$result = $this->db->fetchRow($select);
echo $result->columnNameToFetch;

No comments: