ID:               32347
 User updated by:  auroraeosrose at hotmail dot com
 Reported By:      auroraeosrose at hotmail dot com
-Status:           Open
+Status:           Closed
 Bug Type:         Feature/Change Request
 Operating System: irrelevant
 PHP Version:      5CVS-2005-03-17 (dev)
 New Comment:

__isset and __unset implemented in 5.1 - THANKS!


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

[2005-03-17 04:42:41] auroraeosrose at hotmail dot com

Description:
------------
when implementing the ArrayAccess (spl stuff) interface you can create
a offsetExists() which hooks into calling isset on your object e.g.
isset($object[offset]) (by the way, I love you marcus)

but when using __get and __set with objects, isset becomes absolutely
useless and there is no way to tell what you've set with __set, and
it's annoying to do something like returning NULL from __get and then
doing is_nulls everywhere

Please please please please can we get an __isset hook somehow - spl,
overloading, something???  I've read the whole argument
(http://bugs.php.net/bug.php?id=29917) about how __isset would have to
be called for every property, well can it be hooked so it would only be
called for public or properties that regular isset shoots back false?
this is a major pain in the butt, I'd take the slowdown for the
functionality any day

Reproduce code:
---------------
class data implements ArrayAccess
{
        protected $array;

        public function __construct(&$array)
        {
                $this->array =& $array;
                return;
        }

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

        public function __set($offset, $value)
        {
                return $this->offsetSet($offset, $value);
        }

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

        public function offsetGet($offset)
        {
                if(isset($this->array[$offset]))
                {
                        return $this->array[$offset];
                }
                return;
        }

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

        public function offsetUnset($offset)
        {
                if(isset($this->array[$offset]))
                {
                        unset($this->array[$offset]);
                }
                return;
        }
}

$array = array('one' => 1, 'two' => 2, 'three' => 3, 'four' => 4);
$class = new data($array);
var_dump(isset($class['one']));
var_dump(isset($class->one));

Expected result:
----------------
bool(true)
bool(true)

Actual result:
--------------
bool(true)
bool(false)


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


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

Reply via email to