ZF-10665: Zend_Http_UserAgent may die on serialization

Issue Type: Bug Created: 2010-11-09T14:25:35.000+0000 Last Updated: 2011-01-22T11:42:55.000+0000 Status: Resolved Fix version(s): - 1.11.3 (01/Feb/11)

Reporter: Kevin Schroeder (kschroeder) Assignee: Business&Decision / Interakting (interakting) Tags: - Zend_Http_UserAgent

Related issues: Attachments: - ZF-10665-rtuin.patch


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.


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:

<pre class="highlight">
    public function serialize()
        $spec = array(
            'browser_type' => $this->_browserType,
            'config'       => $this->_config,
            'device_class' => get_class($this->getDevice()),
            'device'       => $this->getDevice()->serialize(),
            'user_agent'   => $this->getServerValue('http_user_agent'),
            'http_accept'  => $this->getServerValue('http_accept'),
        return serialize($spec);

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.

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.