|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52794 $a = $b = $c = $d logic with ArrayObject
Submitted: 2010-09-07 16:53 UTC Modified: 2010-09-07 19:52 UTC
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: seroshkin at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.3.3 OS:
Private report: No CVE-ID: None
 [2010-09-07 16:53 UTC] seroshkin at gmail dot com
If i use expression like
$a = $b = $c = $d;

where $b or $c determined as class extends ArrayObject, then
ArrayObject::offsetGet method do not call.

It may be only if above expression interpreted as
$a = $d;
$b = $d;
$c = $d;

Test script:
class foo extends ArrayObject{
  function offsetGet($index){return 'Ok';}
$o = new foo();
$a = $o[1];
$b = ($o[1] = 'Fail');
echo $a,$b;
//Output: OkFail

//but if

$o[1] = 'Fail';
$b = $o[1];
echo $a,$b;
//Output: OkOk


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-07 19:52 UTC]
-Status: Open +Status: Bogus
 [2010-09-07 19:52 UTC]
This is not a bug.

You did not override offsetSet. The assignment returns the assigned value, hence $b will be 'Fail' in the first example.

However, in the second, despite $o[1] = 'Fail';, $o[1] will return 'Ok' due to your definition of offsetGet and $b will be 'Ok'.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Jul 03 05:03:40 2022 UTC