#43583 [Opn]: Empty function fails when examining property of object accessed through __get

From: Date: Wed, 12 Dec 2007 21:50:23 +0000
Subject: #43583 [Opn]: Empty function fails when examining property of object accessed through __get
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-120617@lists.php.net to get a copy of this message
ID: 43583 Updated by: felipe@php.net Reported By: michael at dmgx dot com Status: Open Bug Type: Variables related Operating System: Linux PHP Version: 5.2.5 New Comment: In PHP 5.3 it works fine. Previous Comments: ------------------------------------------------------------------------ [2007-12-12 19:07:07] michael at dmgx dot com Description: ------------ Empty returns false whenever a property of an object is accessed through __get. This problem has been reported before. The answer that "it's a feature" is entirely bogus - Either return the right value or throw a damn error but don't do nothing and leave people to wonder what the Hell is going on with their script. I just lost two full days to this "feature" and I'm not amused. empty(someFunction()); throws an error. If this bug is too much trouble to fix set it up so empty($object->property); also throws an error when a __get has been set. Reproduce code: --------------- class foo { protected $data = array(); public function __set($element, $value) { $this->data[$element] = $value; } public function __get($element) { return $this->data[$element]; } } $bar = new foo(); $bar->cat = 'meow'; empty($bar->cat); // returns false, as expected. $bar->cat = ''; empty($bar->cat); // returns false, should return true. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43583&edit=1

« previous php.bugs (#120617) next »