Bug #77605 [Opn->Nab]: Incorrect behavior of empty() function is

From: Date: Mon, 11 Feb 2019 19:16:23 +0000
Subject: Bug #77605 [Opn->Nab]: Incorrect behavior of empty() function is
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219511@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77605&edit=1 ID: 77605 Updated by: requinix@php.net Reported by: ezepovarthur at gmail dot com Summary: Incorrect behavior of empty() function is -Status: Open +Status: Not a bug Type: Bug -Package: Performance problem +Package: *General Issues Operating System: CentOS Linux release 7.6.1810 PHP Version: 7.2Git-2019-02-11 (Git) Block user comment: N Private report: N New Comment: Implement __isset. Previous Comments: ------------------------------------------------------------------------ [2019-02-11 19:14:59] ezepovarthur at gmail dot com Description: ------------ PHP 7.2.14 (cli) (built: Jan 8 2019 14:05:15) ( NTS ) [PHP Modules] apcu bcmath bz2 calendar Core ctype curl date dom exif fileinfo filter ftp gd geoip gettext hash iconv igbinary imagick intl json ldap libxml mbstring mcrypt memcached mongodb msgpack mysqli mysqlnd openssl pcntl pcre PDO pdo_mysql pdo_sqlite Phar posix readline redis Reflection session shmop SimpleXML soap sockets SPL sqlite3 standard sysvmsg sysvsem sysvshm tokenizer wddx xdebug xml xmlreader xmlrpc xmlwriter xsl Zend OPcache zip zlib [Zend Modules] Xdebug Zend OPcache Script: we do not have in the test script an exception, since empty() says, in this particular case, that randomProperty of Consumer instance is empty, meanwhile in_array() works correctly and goes through an array [1,2]. Test script: --------------- class BaseEntity { /** * @var array */ protected $globalStack = []; /** * @param $arg * @param $value */ public function __set($arg, $value): void { if (property_exists($this, $arg)) { $this->{$arg} = $value; } else { $this->globalStack[$arg] = $value; } } /** * @param $arg * @return mixed|null */ public function __get($arg) { if (property_exists($this, $arg) && isset($this->{$arg})) { $value = $this->{$arg}; } elseif (isset($this->globalStack[$arg])) { $value = $this->getGlobalStackValue($arg); } else { $value = null; } return $value; } public function getGlobalStackValue($arg) { return $this->globalStack[$arg]; } } class Consumer extends BaseEntity {} $consumer = new Consumer(); $consumer->randomProperty = [1,2]; if (!empty($consumer->randomProperty) && !in_array(4, $consumer->randomProperty)) { throw new \Exception('whatever'); } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77605&edit=1

« previous php.bugs (#219511) next »