From:             phpa dot 20 dot crgtk at spamgourmet dot com
Operating system: Windows XP/2003 but not relevant
PHP version:      5CVS-2006-08-18 (snap)
PHP Bug Type:     Scripting Engine problem
Bug description:  __set "overloading" and language incongruency with arrays

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 bug report at http://bugs.php.net/?id=38507&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=38507&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=38507&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=38507&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=38507&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=38507&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=38507&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=38507&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=38507&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=38507&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=38507&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=38507&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=38507&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=38507&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=38507&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=38507&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=38507&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=38507&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=38507&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=38507&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=38507&r=mysqlcfg

Reply via email to