php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54984 ArrayObject creates invalid variable reference
Submitted: 2011-06-03 12:49 UTC Modified: 2011-06-12 01:00 UTC
From: pwharman at gmail dot com Assigned:
Status: Wont fix Package: SPL related
PHP Version: 5.2.17 OS: Windows/Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: pwharman at gmail dot com
New email:
PHP Version: OS:

 

 [2011-06-03 12:49 UTC] pwharman at gmail dot com
Description:
------------
If ArrayAccess is extended and then the subclass accessed using object notation then unpredicatable results occur. In the test script below an undefined variable $xyz is somehow referencing the ArrayObject subclass Foo.

The same result occurs on Linux systems.

This came to light when using an unitialised value in the Zend Framework Zend_Registry class, although it is not limited to that.

Test script:
---------------
<?php
class Foo extends ArrayObject{
    public function __construct(){
        parent::__construct(array(), parent::ARRAY_AS_PROPS);
    }
}
$f = new Foo;
$f->Foo['bar'] = 1;
var_dump($xyz['xyz']); # This should throw a warning then null??
?>

Expected result:
----------------
PHP Notice:  Undefined index:  Foo in C:\jirasource\ABC\sites\partners.rfp-gener
ator.com\web\test.html.php on line 8
PHP Stack trace:
PHP   1. {main}() C:\jirasource\ABC\sites\partners.rfp-generator.com\web\test.ht
ml.php:0

Notice: Undefined index:  Foo in C:\jirasource\ABC\sites\partners.rfp-generator.
com\web\test.html.php on line 8

Call Stack:
    0.0212      60112   1. {main}() C:\jirasource\ABC\sites\partners.rfp-generat
or.com\web\test.html.php:0

PHP Notice:  Undefined variable: xyz in C:\jirasource\ABC\sites\partners.rfp-gen
erator.com\web\test.html.php on line 9
PHP Stack trace:
PHP   1. {main}() C:\jirasource\ABC\sites\partners.rfp-generator.com\web\test.ht
ml.php:0

Notice: Undefined variable: xyz in C:\jirasource\ABC\sites\partners.rfp-generato
r.com\web\test.html.php on line 9

Call Stack:
    0.0212      60112   1. {main}() C:\jirasource\ABC\sites\partners.rfp-generat
or.com\web\test.html.php:0

PHP Notice:  Undefined index:  xyz in C:\jirasource\ABC\sites\partners.rfp-gener
ator.com\web\test.html.php on line 9
PHP Stack trace:
PHP   1. {main}() C:\jirasource\ABC\sites\partners.rfp-generator.com\web\test.ht
ml.php:0

Notice: Undefined index:  xyz in C:\jirasource\ABC\sites\partners.rfp-generator.
com\web\test.html.php on line 9

Call Stack:
    0.0212      60112   1. {main}() C:\jirasource\ABC\sites\partners.rfp-generat
or.com\web\test.html.php:0

null

Actual result:
--------------
PHP Notice:  Undefined index:  Foo in C:\jirasource\ABC\sites\partners.rfp-gener
ator.com\web\test.html.php on line 8
PHP Stack trace:
PHP   1. {main}() C:\jirasource\ABC\sites\partners.rfp-generator.com\web\test.ht
ml.php:0

Notice: Undefined index:  Foo in C:\jirasource\ABC\sites\partners.rfp-generator.
com\web\test.html.php on line 8

Call Stack:
    0.0212      60112   1. {main}() C:\jirasource\ABC\sites\partners.rfp-generat
or.com\web\test.html.php:0

PHP Notice:  Undefined variable: xyz in C:\jirasource\ABC\sites\partners.rfp-gen
erator.com\web\test.html.php on line 9
PHP Stack trace:
PHP   1. {main}() C:\jirasource\ABC\sites\partners.rfp-generator.com\web\test.ht
ml.php:0

Notice: Undefined variable: xyz in C:\jirasource\ABC\sites\partners.rfp-generato
r.com\web\test.html.php on line 9

Call Stack:
    0.0212      60112   1. {main}() C:\jirasource\ABC\sites\partners.rfp-generat
or.com\web\test.html.php:0

PHP Notice:  Undefined index:  xyz in C:\jirasource\ABC\sites\partners.rfp-gener
ator.com\web\test.html.php on line 9
PHP Stack trace:
PHP   1. {main}() C:\jirasource\ABC\sites\partners.rfp-generator.com\web\test.ht
ml.php:0

Notice: Undefined index:  xyz in C:\jirasource\ABC\sites\partners.rfp-generator.
com\web\test.html.php on line 9

Call Stack:
    0.0212      60112   1. {main}() C:\jirasource\ABC\sites\partners.rfp-generat
or.com\web\test.html.php:0

array(1) {
  ["bar"]=>
  int(1)
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-06-04 01:25 UTC] felipe@php.net
-Status: Open +Status: Feedback
 [2011-06-04 01:25 UTC] felipe@php.net
This makes no sense, Are you reproducing it just with this posted test script?!
 [2011-06-04 13:50 UTC] pwharman at gmail dot com
-Status: Feedback +Status: Open -PHP Version: 5.3.6 +PHP Version: 5.2.17
 [2011-06-04 13:50 UTC] pwharman at gmail dot com
I agree it makes no sense!

I have just retested using PHP 5.3.6 and can not reproduce this, it seems limited to 5.2.x. I have just ran the script against 5.2.17 and can confirm the problem exists.
 [2011-06-12 01:00 UTC] felipe@php.net
-Status: Open +Status: Wont fix
 [2011-06-12 01:00 UTC] felipe@php.net
Since 5.2.x is not a maintained version, consider using 5.3. :)
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC