Req #43936 [Com]: __empty() magic method
| From: | chrisstocktonaz at gmail dot com | Date: | Wed, 24 Aug 2011 00:40:26 +0000 |
| Subject: | Req #43936 [Com]: __empty() magic method | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-162882@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
Comment by: chrisstocktonaz at gmail dot com
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:
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
Previous Comments:
------------------------------------------------------------------------
[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)
------------------------------------------------------------------------
[2010-06-30 13:02:14] pajoye@php.net
Let document the __isset requirements better, when one relies on empty.
------------------------------------------------------------------------
[2010-06-30 12:00:35] icy at lighttpd dot net
Simple test script to trigger the bug:
<?php
class Foo {
public $vars;
function Foo() {
$this->vars['bar'] = 1;
}
function __get($var) {
return $this->vars[$var];
}
}
$foo = new Foo;
var_dump(empty($foo->bar));
$baz = $foo->bar;
var_dump(empty($baz));
Expected result:
----------------
bool(false) bool(false)
Actual result:
--------------
bool(true) bool(false)
------------------------------------------------------------------------
[2010-06-30 11:51:54] pajoye@php.net
hi Dmitry,
What's your thoughts on this one? Someone asked me about it and we found this old bug.
A workaround is to implement __isset but that makes little sense (isset != empty) and is counter
intuitive.
------------------------------------------------------------------------
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