php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53277 Setting previously undefined property on an ArrayObject triggers weird error
Submitted: 2010-11-09 12:29 UTC Modified: 2010-11-09 13:19 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: php dot net at site dot lanzz dot org Assigned:
Status: Wont fix Package: *Programming Data Structures
PHP Version: 5.2.14 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
36 - 7 = ?
Subscribe to this entry?

 
 [2010-11-09 12:29 UTC] php dot net at site dot lanzz dot org
Description:
------------
When assigning a reference to a previously undefined property of an ArrayObject, 
E_NOTICE is thrown on the assignment itself, and every time that property is 
accessed after that. Despite the "undefined index" complaints, the code works as 
expected — $b->test[] = "foo" successfully assigns "foo" to $a[0].

This issue does not occur with assignment by value — no notices are displayed 
(though the code no longer works as intended, as $a[0] remains undefined). It also 
does not occur if $b->test is initialized prior to the assignment by reference 
(e.g. adding a "$b->test = true" row before the assignment) — in this case the 
assignment by reference also works as intended, and does not emit E_NOTICE.

Test script:
---------------
error_reporting(E_ALL & E_STRICT);
ini_set('display_errors', 1);

$a = array();
$b = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
$b->test = &$a;
$b->test[] = "foo";
print($a[0]);

Expected result:
----------------
Script should run without notices.

Actual result:
--------------
Script throws "Undefined index: test" notices every time $b->test is referenced, 
even though everything works correctly otherwise.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-09 13:09 UTC] php dot net at site dot lanzz dot org
Oops, first row should read "error_reporting(E_ALL | E_STRICT)", the notice is not 
visible as it is now.
 [2010-11-09 13:19 UTC] cataphract@php.net
-Status: Open +Status: Wont fix
 [2010-11-09 13:19 UTC] cataphract@php.net
This bug isn't present in PHP 5.3 and trunk, only PHP 5.2

As PHP 5.2 is only receiving security fixes, I'm closing as WONT FIX.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Nov 20 01:01:30 2019 UTC