ID: 38507
Updated by: [EMAIL PROTECTED]
Reported By: phpa dot 20 dot crgtk at spamgourmet dot com
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Windows XP/2003 but not relevant
PHP Version: 5CVS-2006-08-18 (snap)
New Comment:
__get() returns a value, not a reference, so you can't change the
result of __get() and expect the object's attribute to change also.
Previous Comments:
------------------------------------------------------------------------
[2006-08-20 09:41:22] ruslan dot kyrychuk at gmail dot com
$instance->dynmember['language'] = $piece;
will get array by __get overload and than set array value in memory.
This is simple and clear logic.
With your expected result you must override __set property additionaly
for arrays and simple objects.
------------------------------------------------------------------------
[2006-08-19 00:26:12] phpa dot 20 dot crgtk at spamgourmet dot com
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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=38507&edit=1