ZF-10665: Zend_Http_UserAgent may die on serialization
Description
When serializing a user agent, for example, during a unit test for which there is no device, a fatal error is thrown.
Debug Error: D:\Program Files (x86)\Zend\ZendServer\share\ZendFramework-1.11.0\library\Zend\Http\UserAgent.php line 178 - Call to a member function serialize() on a non-object
public function serialize()
{ $spec = array( 'browser_type' => $this->_browserType, 'config' => $this->_config, 'device_class' => get_class($this->_device), 'device' => $this->_device->serialize(), <--- This is the offending call 'user_agent' => $this->getServerValue('http_user_agent'), 'http_accept' => $this->getServerValue('http_accept'), ); return serialize($spec); }
This is presumably due to the fact that I have a user agent resource loading up using Zend_Application during a unit test, for which no device can be found.
Comments
Posted by René Treffer (treffer) on 2011-01-16T17:59:22.000+0000
This problem is very simple:
_device is *lazy loaded* and initialized in getDevice(). This means that any direct reference to _device will break, even within the class.
The fix can be as easy as using this:
Would be happy if someone could check this in.
Posted by Richard Tuin (richardtuin) on 2011-01-22T08:42:37.000+0000
Made a fix patch for René Treffer's fix, and enclosed a unit test in the file: ZF-10665-rtuin.patch
Posted by Ramon Henrique Ornelas (ramon) on 2011-01-22T11:42:52.000+0000
Fixed in trunk r23661 merged to branch release 1.11 r23662.