Hello -

I think there is a bug or a paradox in the php 5 object model implementation.

This is an example :

<?php

class foo implements arrayAccess
{
   private $array = array();

   function __construct() {}

   function __get($key)
   {
      return $this->offsetGet($key);
   }

   function __set($key, $value)
   {
      $this->offsetSet($key, $value);
   }

   function offsetExists($key)
   {
      return isset($this->array[$key]);
   }

   function offsetGet($key)
   {
      return $this->array[$key];
   }

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

   function offsetUnset($key)
   {
      unset($this->array[$key];
   }
}

$foo = new foo();

echo (isset($foo['bar']) == true ? 'set' : 'not set');
$foo['bar'] = 'bar';
echo (isset($foo['bar']) == true ? 'set' : 'not set');
echo $foo['bar'];

#Expected result :
# not set
# set
# bar
#Real result
# not set
# set
# bar
# !! GREAT !!

#Now, the same thing with __get() and __set()

unset($foo);
$foo = new foo();

echo (isset($foo->array) == true ? 'array is set' : 'array is not set');
echo (isset($foo->bar) == true ? 'bar is set' : 'bar is not set');
$foo->bar = 'bar';
echo (isset($foo['bar']) == true ? 'bar is set' : 'bar is not set');
echo $foo->bar;

#Expected result :
# array is set
# bar is not set
# bar is set
# bar
#Real result
# array is set # Ok !
# bar is not set # Ok !
# bar is not set # PROBLEM PROBLEM
# bar
# !! NOT GREAT !!

?>

It is very strange.
isset() does not return the good value on property wich was set with __set() !!
But isset() return the good value on property wich was set in the class !!
And isset() return the good value on value wich was set with offsetSet() method !!
It is a paradox !


I think that isset MUST return the same value in all case.

What do you think of ?

Fred.

Warning : the php code may be wrong (parse error...), i can not validate it in php5 currently

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to