From:             auroraeosrose at hotmail dot com
Operating system: irrelevant
PHP version:      5CVS-2005-03-17 (dev)
PHP Bug Type:     Feature/Change Request
Bug description:  Match overloading behavior to ArrayAccess behavior

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 bug report at http://bugs.php.net/?id=32347&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=32347&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=32347&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=32347&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=32347&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=32347&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=32347&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=32347&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=32347&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=32347&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=32347&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=32347&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=32347&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=32347&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=32347&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=32347&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=32347&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=32347&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=32347&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=32347&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=32347&r=mysqlcfg

Reply via email to