From: Operating system: PHP version: 5.2.13 Package: SPL related Bug Type: Bug Bug description:ArrayObject shows inconsistent behaviour
Description: ------------ This bug refers to my report filed under http://bugs.php.net/bug.php?id=34783 which is now more than four years old. In the meantime I found out that using ArrayObject instead of the test class the $t['huba'][]='three'; actually works, thanks to the SPL using its "implemented in C advantage" to circumvent the problem. Actually, it works until the programmer decides to inherit from ArrayObject and overwrite offsetGet(). Then the problem of the offsetGet() method not returning by reference is back. Back in 2005 you were very quick to flag the report as BOGUS, but a look at the source code of "zend_interfaces.c" proves that there is in fact a problem: ZEND_BEGIN_ARG_INFO_EX(arginfo_arrayaccess_offset_get, 0, 0, 1) /* actually this should be return by ref but atm cannot be */ The best way of dealing with this is not to mark it as BOGUS and deny that there is a problem. It would be admitting the fault and perhaps introducing an alternative NewArrayAccess interface that defines &offsetGet(). So future code can use it without breaking old implementations. Test script: --------------- <?php class Test1 extends ArrayObject { } class Test2 extends ArrayObject { function offsetGet($key) { return parent::offsetGet($key); } } $t1 = new Test1(); $t1['huba'] = array('one','two'); $t1['huba'][] = 'three'; print_r($t1); $t2 = new Test2(); $t2['huba'] = array('one','two'); $t2['huba'][] = 'three'; print_r($t2); Expected result: ---------------- Test1 Object ( [huba] => Array ( [0] => one [1] => two [2] => three ) ) Test2 Object ( [huba] => Array ( [0] => one [1] => two [2] => three ) ) Actual result: -------------- Test1 Object ( [huba] => Array ( [0] => one [1] => two [2] => three ) ) Notice: Indirect modification of overloaded element of Test2 has no effect in F:\huba.php on line 17 Test2 Object ( [huba] => Array ( [0] => one [1] => two ) ) -- Edit bug report at http://bugs.php.net/bug.php?id=51622&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=51622&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=51622&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=51622&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=51622&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51622&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=51622&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=51622&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=51622&r=needscript Try newer version: http://bugs.php.net/fix.php?id=51622&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=51622&r=support Expected behavior: http://bugs.php.net/fix.php?id=51622&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=51622&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=51622&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=51622&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51622&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=51622&r=dst IIS Stability: http://bugs.php.net/fix.php?id=51622&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=51622&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=51622&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=51622&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=51622&r=mysqlcfg