Bug #66249 [Nab]: empty() returns true, when it shouldn't on an object
| From: | kenyon dot jh at gmail dot com | Date: | Mon, 09 Dec 2013 22:32:55 +0000 |
| Subject: | Bug #66249 [Nab]: empty() returns true, when it shouldn't on an object | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-183209@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66249&edit=1
ID: 66249
User updated by: kenyon dot jh at gmail dot com
Reported by: kenyon dot jh at gmail dot com
Summary: empty() returns true, when it shouldn't on an object
Status: Not a bug
Type: Bug
Package: Class/Object related
Operating System: Debian
PHP Version: 5.4.22
Block user comment: N
Private report: N
New Comment:
Found it. My bad haha
Previous Comments:
------------------------------------------------------------------------
[2013-12-09 22:24:01] requinix@php.net
It kinda does, actually ;)
"Note:
When using empty() on inaccessible object properties, the __isset() overloading method will be
called, if declared."
------------------------------------------------------------------------
[2013-12-09 22:15:44] kenyon dot jh at gmail dot com
I see, my bad. Is there any way to clarify that in the php.net/empty documentation? That was what I
was using as a reference, and why I was a little confused.
Sorry about that, thanks!
------------------------------------------------------------------------
[2013-12-09 20:48:49] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
You need to implement __isset() too.
In general __get, __set, and __isset come as a triplet: if you have one then you should have all
three.
------------------------------------------------------------------------
[2013-12-09 20:32:37] kenyon dot jh at gmail dot com
Description:
------------
My PHP version wasn't an option, so it is actually "PHP Version 5.4.4-14+deb7u5" and
my system is Linux toshiba 3.2.0-4-amd64 #1 SMP Debian 3.2.51-1 x86_64
Basically, when referencing an variable through a class (I only tested with __set and __get) it
empty() returns true, even when it should return false.
Since it is kind of hard to explain, I posted a script below that demonstrates what I am talking
about.
Test script:
---------------
<?php
class testing {
protected $_response = array();
public function __set($key, $value) {
$this->_response[$key] = $value;
}
public function __get($key) {
return $this->_response[$key];
}
}
$testing = new testing();
$testing->foo = 'bar';
var_dump($testing->foo); //Returns 'string(3) "bar"
var_dump(empty($testing->foo)); //Returns bool(true)
?>
Expected result:
----------------
Line 17 should return bool(false)
Actual result:
--------------
Line 17 actually returns bool(true)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66249&edit=1