|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25124 overload() messes with array member variables
Submitted: 2003-08-18 02:34 UTC Modified: 2004-02-24 10:05 UTC
Avg. Score:4.7 ± 0.7
Reproduced:5 of 5 (100.0%)
Same Version:3 (60.0%)
Same OS:2 (40.0%)
From: ian at ardes dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4CVS-2004-02-11 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: ian at ardes dot com
New email:
PHP Version: OS:


 [2003-08-18 02:34 UTC] ian at ardes dot com
Summary: When a class is overloaded with overload(), 
array member variables go wrong.

If you overload a class, then access to declared array 
member variables from within member functions (and 
anywhere else I think) stops working correctly.

The very simple class in the code should not change 
it's behaviour at all once it is overloaded.  But it 

Reproduce code:
class Overloaded {
    var $_my_array = array();
    function Overloaded() {
        $this->_my_array[1] = '1st element';
    function __get($nm, &$val) {
        return false;
    function __set($nm, $val) {
        return false;

$o1 = new Overloaded();
print ("before overload(): "); print_r($o1);


$o2 = new Overloaded();
print ("after overload():  "); print_r($o2);

Expected result:
before overload(): overloaded Object
    [_my_array] => Array
            [1] => 1st element

after overload(): overloaded Object
    [_my_array] => Array
            [1] => 1st element


Actual result:
before overload(): overloaded Object
    [_my_array] => Array
            [1] => 1st element

after overload():  overloaded Object
    [_my_array] => 1st element


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-17 15:52 UTC]
Overloading of array indexes is not supported. This is expected behavior.
 [2004-02-17 16:37 UTC]
Expected behaviour -> bogus.

 [2004-02-24 10:05 UTC] ian at ardes dot com
I thought that the overload functiality only applied to 
attributes that were not defined: defined attributes are 
passed over by the magic functions.

The example given is of a *defined* attribute being 
messed up, not an example of attempting to overload with 
array indexes.

If this is expected behavior, then I guess the 
disclaimer should read something like 'You cannot use 
array attributes on a class which is overloaded' rather 
than 'Overloading of array indexes is not supported'.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 17 23:01:27 2024 UTC