Bug #77605 [NEW]: Incorrect behavior of empty() function is
| From: | ezepovarthur at gmail dot com | Date: | Mon, 11 Feb 2019 19:14:59 +0000 |
| Subject: | Bug #77605 [NEW]: Incorrect behavior of empty() function is | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-219510@lists.php.net to get a copy of this message | ||
From: ezepovarthur at gmail dot com
Operating system: CentOS Linux release 7.6.1810
PHP version: 7.2Git-2019-02-11 (Git)
Package: Performance problem
Bug Type: Bug
Bug description:Incorrect behavior of empty() function is
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 bug report at https://bugs.php.net/bug.php?id=77605&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77605&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77605&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77605&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77605&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77605&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77605&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77605&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77605&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77605&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77605&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77605&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77605&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77605&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77605&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77605&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77605&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77605&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77605&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77605&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77605&r=mysqlcfg