php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33582 ArrayAccess - getOffset doesn't work
Submitted: 2005-07-06 10:17 UTC Modified: 2005-07-13 11:45 UTC
From: tomas_matousek at hotmail dot com Assigned: helly (profile)
Status: Not a bug Package: SPL related
PHP Version: 5.1.0b2 OS: WinXP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tomas_matousek at hotmail dot com
New email:
PHP Version: OS:

 

 [2005-07-06 10:17 UTC] tomas_matousek at hotmail dot com
Description:
------------
Since you fixed this issue:
"Fixed inheritance check to control return by reference and pass by reference correctly (ArrayAccess can no longer support references correctly)."

offsetGet doesn't work correctly not only with references.

I would suggest you to change interface and require return by reference for offsetGet. This would fix also issues regarding references. 

Reproduce code:
---------------
class C { public $x; }
$z = new C;

class ArrayClass implements ArrayAccess 
{
    function offsetGet($index) 
    {
        global $z;
        $result = array("obj" => $z);
        return $result;
    }
    
    function offsetSet($index, $newval) { }
    function offsetExists($index) { }
    function offsetUnset($index) { }
}

$obj = new ArrayClass();
$obj["index"]["obj"]->x = 10;

Expected result:
----------------
I would expect no error. The code is imho correct.

Actual result:
--------------
Fatal error:  Objects used as arrays in post/pre increment/decrement must return values by reference.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-13 11:45 UTC] tony2001@php.net
Duplicate of bug #32983.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 12:01:27 2024 UTC