Bug #52794 [Opn->Bgs]: $a = $b = $c = $d logic with ArrayObject

From: Date: Tue, 07 Sep 2010 17:52:50 +0000
Subject: Bug #52794 [Opn->Bgs]: $a = $b = $c = $d logic with ArrayObject
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-154159@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=52794&edit=1 ID: 52794 Updated by: cataphract@php.net Reported by: seroshkin at gmail dot com Summary: $a = $b = $c = $d logic with ArrayObject -Status: Open +Status: Bogus Type: Bug Package: Arrays related PHP Version: 5.3.3 Block user comment: N New Comment: 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'. Previous Comments: ------------------------------------------------------------------------ [2010-09-07 16:53:29] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52794&edit=1

« previous php.bugs (#154159) next »