|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64417 BC break: ArrayAccess::&offsetGet() in a trait causes fatal error.
Submitted: 2013-03-12 22:39 UTC Modified: 2013-03-19 09:27 UTC
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: me at fixxxer dot me Assigned: dmitry
Status: Closed Package: Scripting Engine problem
PHP Version: 5.4Git-2013-03-12 (snap) OS: any
Private report: No CVE-ID:
 [2013-03-12 22:39 UTC] me at fixxxer dot me

"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 

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:
// This code is mostly the same as in the
// 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) {
    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;
echo $o['x'], "\n";

Expected result:
$ ./php-5.4.10/sapi/cli/php OffsetGet.php 


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


trait_arrayaccess_get_ref.patch (last revision 2013-03-12 22:39 UTC) by me at fixxxer dot me)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-14 13:44 UTC]
-Assigned To: +Assigned To: dmitry
 [2013-03-14 13:44 UTC]
dmitry, please look at this one.
 [2013-03-19 09:15 UTC]
-Status: Assigned +Status: Closed
 [2013-03-19 09:15 UTC]
Automatic comment on behalf of
Log: Fixed bug #64417 (ArrayAccess::&amp;offsetGet() in a trait causes fatal error)
 [2013-03-19 09:27 UTC]
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at

 For Windows:
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Fri Apr 18 15:02:26 2014 UTC