Req #43936 [Opn->Wfx]: __empty() magic method
| From: | nikic@php.net | Date: | Sun, 20 Mar 2016 17:36:29 +0000 |
| Subject: | Req #43936 [Opn->Wfx]: __empty() magic method | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-199968@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=43936&edit=1
ID: 43936
Updated by: nikic@php.net
Reported by: james dot laver at gmail dot com
Summary: __empty() magic method
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
Package: Class/Object related
Operating System: GNU/Linux
PHP Version: 5.2.5
Block user comment: N
Private report: N
New Comment:
This functionality is already supported, you simply need to implement both __isset() and __get().
empty($foo->bar) is semantically identical to !isset($foo->bar) || !$foo->bar. As such, a
meaningful handling of empty() requires both of these handlers to be implemented.
Previous Comments:
------------------------------------------------------------------------
[2012-07-20 13:53:32] thomas at sibben dot nl
reproducable with:
class Test {
private $test;
function __construct($test)
{
$this->test = $test;
}
public function __get($key)
{
return $this->$key;
}
public function getTest()
{
return $this->test;
}
}
$test = new Test('test');
if (!empty($test->test)) {
echo $test->test;
} else {
echo 'empty';
}
echo '<br />';
echo $test->test;
echo '<br />';
echo $test->getTest();
------------------------------------------------------------------------
[2012-07-20 13:44:41] thomas at sibben dot nl
The documentation states:
"empty() only checks variables as anything else will result in a parse error"
if 'everything else' is a __get() returning an array with a value in it, it returns TRUE,
Ubuntu 10.04 PHP 5.3.2-1ubuntu4.17
------------------------------------------------------------------------
[2011-08-24 00:40:26] chrisstocktonaz at gmail dot com
I made the start of a patch for this, but there is some issues that would need to
be worked out with has_property calls, it seems oddly interfaced with by the
various callers.
http://pastebin.com/d5gQycDB
------------------------------------------------------------------------
[2010-10-23 16:08:03] kalle@php.net
Fixed the overloading property vs language construct issue in the documentation.
This feature request is still valid, so moving it to be one instead of a documentation issue
------------------------------------------------------------------------
[2010-10-23 16:06:52] kalle@php.net
Automatic comment from SVN on behalf of kalle
Revision: http://svn.php.net/viewvc/?view=revision&revision=304662
Log: Added a remark about overloaded properties and language constructs (Bug #43936)
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=43936
--
Edit this bug report at https://bugs.php.net/bug.php?id=43936&edit=1