ZF-3705: Zend_Rest_Client_Result does not check if its operating on an object instance


One of the reasons to use the rest client is to get convenient overloading behavior. However if the expected structure of the result does not match, then I can end up with a fatal error unless I manually check.

For example: $pricesList = new Zend_Rest_Client($url); $result = $pricesList->get(); $result->pricesxmlexport->pricesgroup->price

I can easily end up with a fatal error here if the document does not match my expectations. This is due to the fact that the __get() method in Zend_Rest_Client_Result does not check if it can even call the xpath() method in $this->_sxml before calling it.


a new class may be created to fix it :

Zend/Rest/Client/Result/Exception.php :

class Zend_Rest_Client_Result_Exception extends Zend_Rest_Client_Exception {}

and after line 43 of Zend/Rest/Client/Result.php:

    $this->_sxml = simplexml_load_string($data);

add :

    if (false === $this->_sxml) {
            throw new Zend_Rest_Client_Result_Exception('simplexml cannot load result data');

This looks like it is related to ZF-3647 and the fix is very similar

Fixed in trunk. Implementation is using a simple error handler for the Xml parsing to show a specific error message.

Changing issues in preparation for the 1.7.0 release.