|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-05-12 12:32 UTC] pecoes at xs4all dot nl
Description: ------------ It's pretty counter-intuitive, that you can neither access an ArrayObject's properties with the array-syntax, nor its array-values with the object-syntax. I think these two should be interchangeable. Preferably like in ECMAScript... Reproduce code: --------------- $a = new ArrayObject(); $a->one = 1; $a['two'] = 2; echo "\$a->one: $a->one \$a->two: $a->two \n"; echo "\$a[one]: $a[one] \$a[two]: $a[two] \n"; Expected result: ---------------- $a->one: 1 $a->two: 2 $a[one]: 1 $a[two]: 2 Actual result: -------------- $a->one: 1 $a->two: $a[one]: $a[two]: 2 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 03:00:01 2025 UTC |
Yep it's me alone. I'll do something as soon as i find ime then. How about some exchangeArray() method that drops the current array and replaces it with the given one. So the following would do what you want: class ArrayObjectEx extends ArrayObject { function __construct() { $this->exchangeArray($this); } } $obj = new ArrayObjectEx;Turns out the work-around is not terribly complicated: class ArrayObject2 extends ArrayObject { function __set($prop, $val) { parent::offsetSet($prop, $val); } function __get($prop) { return parent::offsetGet($prop); } } Could you turn that into the default behaviour?