ID:               29917
 Updated by:       [EMAIL PROTECTED]
 Reported By:      dasch at ulmail dot net
 Status:           Bogus
 Bug Type:         Class/Object related
 Operating System: Linux
 PHP Version:      5.0.1
 New Comment:

No, you're wrong. The behavior you see is the correct behavior.


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

[2004-09-01 09:59:01] fch at hexanet dot fr

<?php

class OO
{
        private $array = array();

        function __construct() {}

        function __set($name, $value)
        {
                $this->array[$name] = $value;
        }

        function __get($name)
        {
                if (isset($this->array[$name]) == true)
                        return null;
                else
                        return $this->array[$name];
        }
}

$o = new oo();
$o->foo = 'bar';
echo (isset($o->foo) == true ? 'foo is set' : 'foo is not set');

#Expecting result
# => foo is set
#Real result
# => foo is not set

?>

If PHP provide __set() and __get() function in order to create property
dynamicaly, PHP function like isset() MUST BE USED with these "dynamic"
properties as usual.
So, in my example, isset() MUST return TRUE !! and not FALSE !!

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

[2004-09-01 08:41:52] [EMAIL PROTECTED]

This works fine for me:

[EMAIL PROTECTED]:~$ cat bug29917.php
<?php
        class oo {
                var $a;
        }

        $o = new oo;
        echo isset($o->a) ? "yes\n" : "no\n";
        $o->a = 'bar';
        echo isset($o->a) ? "yes\n" : "no\n";
?>
[EMAIL PROTECTED]:~$ php bug29917.php
no
yes


Come up with a short example like mine that shows that it doesn't work.
Just saying $o->a won't work doesn't help.

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

[2004-08-31 19:35:52] dasch at ulmail dot net

Still not resolved, you still have to use the following code to access
the properties:

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

Another guy thought that it would be neat if there was a __isset magic
method.

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

[2004-08-31 16:27:11] fch at hexanet dot fr

Sorry, but if you do that :
$o->a = 'foo';
echo isset($o->a) ? "yes\n" : "no\n";
Expected result was true, but actual result is false !
And $o->a is set !

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

[2004-08-31 16:20:45] [EMAIL PROTECTED]

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).

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

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/29917

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

Reply via email to