Bug #66249 [Opn->Nab]: empty() returns true, when it shouldn't on an object

From: Date: Mon, 09 Dec 2013 20:48:49 +0000
Subject: Bug #66249 [Opn->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-183206@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 Updated by: requinix@php.net Reported by: kenyon dot jh at gmail dot com Summary: empty() returns true, when it shouldn't on an object -Status: Open +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: 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. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#183206) next »