Edit report at https://bugs.php.net/bug.php?id=43936&edit=1
ID: 43936
Comment by: thomas at sibben dot nl
Reported by: james dot laver at gmail dot com
Summary: __empty() magic method
Status: Open
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:
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();
Previous Comments:
------------------------------------------------------------------------
[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] [email protected]
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] [email protected]
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)
------------------------------------------------------------------------
[2010-06-30 13:02:14] [email protected]
Let document the __isset requirements better, when one relies on empty.
------------------------------------------------------------------------
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