Bug #68654 [NEW]: empty function: late evaluation of argument
| From: | your dot brother dot t at hotmail dot com | Date: | Thu, 25 Dec 2014 21:59:16 +0000 |
| Subject: | Bug #68654 [NEW]: empty function: late evaluation of argument | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-189205@lists.php.net to get a copy of this message | ||
From: your dot brother dot t at hotmail dot com
Operating system: Windows 8.1 64-bit
PHP version: 5.6.4
Package: Scripting Engine problem
Bug Type: Bug
Bug description:empty function: late evaluation of argument
Description:
------------
---
From manual page: http://www.php.net/function.empty
---
5.5.0
empty() now supports expressions, rather than only variables.
---
The
empty() can't evaluate multiple __get() results explicitly.
It seems that instead of correct nesting which is left to right
nesting:
empty(...(((($this)->a)->b)->c)->...)
It uses a right to left nesting:
empty(($this->(a->(b->(c)->...)))...)
Which returns null at the first left-most -> operator, yielding to
an empty call to become true.
Test script:
---------------
<?php
class Juice extends Liquid{
protected $apple;
protected $orange;
public function __get($name) {
return $this->$name;
}
public function __construct($apple, $orange) {
$this->apple = $apple;
$this->orange = $orange;
}
}
class Glass {
protected $liquid;
public function __get($name) {
return $name == "liquid" ? $this->liquid : false;
}
public function __construct() {
$this->juice = new Juice(3, 5);
}
}
$glass = new Glass();
var_dump(empty($this->liquid));
var_dump(empty($this->liquid->apple));
var_dump(empty(($this->liquid->apple)));
?>
Expected result:
----------------
bool(false)
bool(false)
bool(false)
Actual result:
--------------
bool(false)
bool(true)
bool(false)
--
Edit bug report at https://bugs.php.net/bug.php?id=68654&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68654&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68654&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68654&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=68654&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=68654&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=68654&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=68654&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=68654&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=68654&r=support
Expected behavior: https://bugs.php.net/fix.php?id=68654&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=68654&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=68654&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=68654&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68654&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=68654&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=68654&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=68654&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68654&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=68654&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=68654&r=mysqlcfg