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
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: 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

Add a Patch

Pull Requests

Add a Pull Request

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-2019 The PHP Group
All rights reserved.
Last updated: Fri Dec 13 20:01:23 2019 UTC