#29917 [Opn->Bgs]: isset() always return

From: Date: Tue, 31 Aug 2004 14:20:52 +0000
Subject: #29917 [Opn->Bgs]: isset() always return
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-65520@lists.php.net to get a copy of this message
 ID:               29917
 Updated by:       derick@php.net
 Reported By:      dasch at ulmail dot net
-Status:           Open
+Status:           Bogus
 Bug Type:         Class/Object related
 Operating System: Linux
 PHP Version:      5.0.1
 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

This is correct, the isset() checks if a variable is set or not. In
your case it's simply not set (it will be set after __get() is executed
on it once).


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

[2004-08-31 16:00:43] dasch at ulmail dot net

Description:
------------
When trying to determine whether or not a property in an overloaded
object is set, isset() always returns FALSE. This is not the case with
objects that isn't overloaded (doesn't have a __get() method defined).

Reproduce code:
---------------
<?php

class OO
{
	private $elem = array("a" => 1);
	
	public function __get ($prop)
	{
		if (isset($this->elem[$prop])) {
			return $this->elem[$prop];
		} else {
			return NULL;
		}
	}
	
	public function __set ($prop, $val)
	{
		$this->elem[$prop] = $val;
	}
}

$o = new OO();

echo isset($o->a) ? "yes\n" : "no\n";
echo isset($o->b) ? "yes\n" : "no\n";

echo is_null($o->a) ? "yes\n" : "no\n";
echo is_null($o->b) ? "yes\n" : "no\n";

?>

Expected result:
----------------
yes
no
no
yes

Actual result:
--------------
no
no
no
yes


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


-- 
Edit this bug report at http://bugs.php.net/?id=29917&edit=1


Thread (13 messages)

« previous php.bugs (#65520) next »