php.net |  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
Votes:1
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: seroshkin at gmail dot com
New email:
PHP Version: OS:

 

 [2010-09-07 16:53 UTC] seroshkin at gmail dot com
Description:
------------
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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-07 19:52 UTC] cataphract@php.net
-Status: Open +Status: Bogus
 [2010-09-07 19:52 UTC] cataphract@php.net
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-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 13:01:33 2025 UTC