From:             adove at booyahnetworks dot com
Operating system: WinXP, Linux
PHP version:      5.0.5
PHP Bug Type:     SPL related
Bug description:  offsetExists not called in dreived class

Description:
------------
I've searched the bug list and found only one bug that hints arond the
same issue (http://bugs.php.net/bug.php?id=34849) BUT it appears the
closing statement in the bug "ArrayAccess objects don't work in array_*()
functions. You may want to
turn this report into a feature request?" seems incorrect per the code
below. 

I have an class (MyArray) I derived from ArrayObject and have overridden
the ArrayAccess::offset* methods to allow me to make the array addressable
via an XPath-styled key path, e.g., /key1/key2, etc.). All of the offset*
methods get called just fine and work like a champ EXCEPT offsetExists...


Based on the bug ref'd above, offsetExists is just an adjunct function on
the ArrayAccess interface and not "hooked up" to any language constructs.
HOWEVER, based on emperical information, this appears
incorrect/inconsistent. 

The code submited illustrates the point. If I take a raw ArrayObject, set
it to a multi-dim'd array and test for the root key via array_key_exists,
I get true, which is correct. Additionally, if I test for any other key I
get false, which is also correct. Based on the above bug I would expect to
get a warning about only arrays being passed to the method blah blah. So,
somehow it would *appear* that the ArrayObject class is somehow having its
offsetExists method.

When I do the same tests with my derived array object (MyArray), I get the
same results. HOWEVER, my overidden offsetExists method is never called.
This is evident via debuging (I never step into it) and in the last test
assigned to $bShouldWorkButDoesNot. This path actually does exist and
would have  been confirmed to via my offsetExists.

So, I am prepared to be given the same answer as the other bug. ;-) BUT, I
think this is inconsistent behavior so it seems a bug to me... And, if it
is not a bug, then I will 100% submit a feature request. 

Reproduce code:
---------------
$a = array(
    "test" => array(
        "one" => "dunno",
        "two" => array(
            "peekabo" => "do you see me?",
            "anyone" => array("there")
            )
        )
    );
$oArray = new ArrayObject($a);
$oMyArray = new MyArray($a);

$bWorks1 = array_key_exists("test", $oArray);
$bWorks2 = array_key_exists("test", $oMyArray);

$bShouldWorkButDoesNot = array_key_exists("test/two/peekabo",
$oBooyahArray);


Expected result:
----------------
true === $bWorks1
true === $bWorks2
true === $bShouldWorkButDoesNot

Actual result:
--------------
true === $bWorks1
true === $bWorks2
false === $bShouldWorkButDoesNot

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

Reply via email to