Issues

ZF-12450: Zend_Http_UserAgent_AbstractDevice hasFeature-Function does not work for (Boolean)false-values

Issue Type: Bug Created: 2012-10-22T14:27:58.000+0000 Last Updated: 2012-11-16T15:23:56.000+0000 Status: Resolved Fix version(s): - 1.12.1 (18/Dec/12)

Reporter: Simon Echle (echle) Assignee: Business&Decision / Interakting (interakting) Tags: - Zend_Http_UserAgent

Related issues: Attachments:

Description

If the value of a feature is (Boolean)false the hasFeature-Function returns false.

Currently looks like this:

<pre class="highlight">
public function hasFeature($feature)
{
    return (!empty($this->_aFeatures[$feature]));
}

I would recommend using "is_null" instead of "empty":

<pre class="highlight">
public function hasFeature($feature)
{
    return(!is_null($this->_aFeatures[$feature]));
}

Comments

Posted by Rob Allen (rob) on 2012-11-06T21:18:16.000+0000

Will a test for is_null() result in a warning if $this->_aFeatures[$feature] doesn't exist?

Posted by Simon Echle (echle) on 2012-11-07T07:20:09.000+0000

Litte testing resultet in the expected warnings. The condition should contain a test for isset() to fix this. The code could look like this:

<pre class="highlight">
public function hasFeature($feature)
{
    return(isset($this->_aFeatures[$feature]) && !is_null($this->_aFeatures[$feature]));
}

Thx to lazy evaluation the is_null expression wont be touched if the array key doesnt exist.

Posted by Rob Allen (rob) on 2012-11-16T15:23:56.000+0000

Fixed on trunk (25128) and release-1.12 (25129)

Have you found an issue?

See the Overview section for more details.

Copyright

© 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.

Contacts