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

From: Date: Thu, 13 Dec 2007 04:23:01 +0000
Subject: #43583 [Com]: 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-120622@lists.php.net to get a copy of this message
 ID:               43583
 Comment by:       crrodriguez at suse dot de
 Reported By:      michael at dmgx dot com
 Status:           Open
 Bug Type:         Variables related
 Operating System: Linux
 PHP Version:      5.2.5
 New Comment:

you have to define __isset magic method.


Previous Comments:
------------------------------------------------------------------------

[2007-12-12 21:50:23] felipe@php.net

In PHP 5.3 it works fine.

------------------------------------------------------------------------

[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


Thread (4 messages)

« previous php.bugs (#120622) next »