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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
38 - 3 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 06:01:29 2024 UTC