|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-07-18 14:25 UTC] jani@php.net
[2007-07-18 14:27 UTC] jani@php.net
[2007-07-19 13:00 UTC] jani@php.net
[2007-07-19 13:23 UTC] luke at liveoakinteractive dot com
[2012-07-09 07:45 UTC] alonso dot vidales at tras2 dot es
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 23 08:00:02 2025 UTC |
Description: ------------ Good morning! I've found what I'm reasonably certain is a bug, and I've searched to verify that nobody has reported the same issue. I see some similar issues reported by others, but I don't think any are identical. Hopefully I'm not beating a dead horse. The issue I've run into is that __get and __set cause odd behavior if you're trying to get or set a piece of an array (e.g. $object->arr[1] = true;). It returns back a notice: "Indirect modification of overloaded property ClassName::$my_array has no effect" (and indeed it doesn't; the assignment or retrieval do not work!). You can get around this by assigning the entire array in advance and then assigning the array as a unit to the object, and retrieving similarly (the entire array first, then in pieces). However, it seems to be the case that I should be able to assign pieces of arrays here just like anywhere else. As an additional note, if the array is an actual class property, it works. Thanks so much for your time! Luke Sneeringer Live Oak Interactive Reproduce code: --------------- <?php class ClassName { private $fields; public $class_array; public function __get($key) { if (isset($this->fields[$key])) { return $this->fields[$key]; } else { return null; } } public function __set($key, $val) { $this->fields[$key] = $val; } } $c = new ClassName; $c->scalar = 'two'; // works $c->an_array[3] = 'three'; // throws notice $diff_array[3] = 'three'; $c->diff_array = $diff_array; // works $c->class_array[4] = 'four'; // works Expected result: ---------------- I would have expected an assignment such as $c->an_array[3] = 'three'; to assign as expected. It certainly seems intuitive that one should be able to assign an array in this manner, and I saw nothing in the documentation indicating otherwise. An array as a whole can be stored this way (as the second working example indicates); there just seems to be something about assigning a particular piece that breaks. Incidentally, retrieving suffers from the same issue...I can retrieve the array as a whole, but not a piece of it. Actual result: -------------- I get an error of level E_NOTICE: Indirect modification of overloaded property ClassName::$an_array has no effect. The assignment or retrieval, as the notice indicates, does not work.