Doc->Req #43936 [Opn]: __empty() magic method
| From: | kalle@php.net | Date: | Sat, 23 Oct 2010 14:08:03 +0000 |
| Subject: | Doc->Req #43936 [Opn]: __empty() magic method | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-155458@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=43936&edit=1
ID: 43936
Updated by: kalle@php.net
Reported by: james dot laver at gmail dot com
Summary: __empty() magic method
Status: Open
-Type: Documentation Problem
+Type: Feature/Change Request
-Package: Documentation problem
+Package: Class/Object related
Operating System: GNU/Linux
PHP Version: 5.2.5
Block user comment: N
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
[2008-01-25 14:40:45] james dot laver at gmail dot com
Description:
------------
Using empty() on a variable that would be pulled from __get does not
work, this has been established as 'not a bug' by more bug reports than
anyone cares to remember, however, the documentation's suggestion of
using __isset is not adequate if you wish to implement both isset and
empty functionality.
Thus I propose an __empty() magic method which would overload empty() in
the way that __isset() overrides isset().
Reproduce code:
---------------
public function __empty($value)
{
return empty($this->_values[$value]);
}
Expected result:
----------------
empty($object->my_empty_value) = true
Actual result:
--------------
.....
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=43936&edit=1