From: me at fixxxer dot me Operating system: any PHP version: 5.4Git-2013-03-12 (snap) Package: Scripting Engine problem Bug Type: Bug Bug description:BC break: ArrayAccess::&offsetGet() in a trait causes fatal error.
Description: ------------ http://www.php.net/manual/en/arrayaccess.offsetget.php "While direct modification triggers a call to ArrayAccess::offsetSet(), indirect modification triggers a call to ArrayAccess::offsetGet(). In that case, the implementation of ArrayAccess::offsetGet() must be able to return by reference, otherwise an E_NOTICE message is raised.". When &offsetGet() is implemented in a trait, this got broken in 5.4.11 with this commit: https://github.com/php/php-src/commit/3f8c729e693c432b438cd33679182260d8732e30 The patch attached just comments out the check which causes the error. There should be a better way to deal with this problem. Test script: --------------- <?php // This code is mostly the same as in the // http://www.php.net/manual/en/class.arrayaccess.php example, // but changed to use traits. trait aa { private $container = array(); public function offsetSet($offset, $value) { if (is_null($offset)) { $this->container[] = $value; } else { $this->container[$offset] = $value; } } public function offsetExists($offset) { return isset($this->container[$offset]); } public function offsetUnset($offset) { unset($this->container[$offset]); } public function &offsetGet($offset) { $result = null; if (isset($this->container[$offset])) { $result = &$this->container[$offset]; } return $result; } } class obj implements ArrayAccess { use aa; } $o = new obj; $o['x'] = 1; ++$o['x']; echo $o['x'], "\n"; Expected result: ---------------- $ ./php-5.4.10/sapi/cli/php OffsetGet.php 2 Actual result: -------------- $ ./php5.4-201303122030/sapi/cli/php OffsetGet.php Fatal error: Declaration of & aa::offsetGet($offset) must be compatible with ArrayAccess::offsetGet($offset) in /home/build/tmp/OffsetGet.php on line 28 -- Edit bug report at https://bugs.php.net/bug.php?id=64417&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=64417&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=64417&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=64417&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=64417&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=64417&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=64417&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=64417&r=needscript Try newer version: https://bugs.php.net/fix.php?id=64417&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=64417&r=support Expected behavior: https://bugs.php.net/fix.php?id=64417&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=64417&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=64417&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=64417&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64417&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=64417&r=dst IIS Stability: https://bugs.php.net/fix.php?id=64417&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=64417&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=64417&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=64417&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=64417&r=mysqlcfg