|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-08-20 09:41 UTC] ruslan dot kyrychuk at gmail dot com
[2006-08-21 08:33 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 07:00:02 2025 UTC |
Description: ------------ Fact: By utilizing the __get() overload functionality in a class, PHP allows one to return a dynamic member of an object as an array that can be used as if the array were an actual static member of the object. [Example (1) below]. Issue: However, a glaring incongruency in the PHP language arrises when one attempts to utilze the __set() overload functionality to modify the given dynamic member array. One can get, but cannot set the dynamic member as if it were an array. [Example (2) below]. Consequence: This situation prevents one from making a drop-in replacement object -- that utilizes dynamic member arrays -- for an object that originally contained static member arrays. Reproduce code: --------------- class MyClass { function __get($name){ return array("hooray"=>"for", "language"=>"incongruencies"); } function __set($name, $value){ echo "set was passed:\n"; echo print_r($name, true)."\n"; echo print_r($value, true)."\n"; } } $instance = new MyClass(); // (1) proof of dynamic member "being" an array print_r($instance->dynmember); // (1) proof of dynamic member array "being accessed" $piece = $instance->dynmember["language"]; echo "piece is: $piece\n\n"; // (2) issue: since one can do the above, one expects to be able to do the following $piece = "being congruent"; $instance->dynmember['language'] = $piece; // as of php 5.2, literally does nothing Expected result: ---------------- Since the language does not seem to have any current capability of detecting this condition, the following is a _proposed_ result of the above code: Array ( [hooray] => for [language] => incongruencies ) piece is: incongruencies set was passed: dynmember Array ( [language] => being congruent ) Actual result: -------------- Please observe that there are no errors in the output below. That is because there are literally no errors raised by PHP; the code fails silently. Array ( [hooray] => for [language] => incongruencies ) piece is: incongruencies