|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68947 BC break accessing object properties
Submitted: 2015-01-29 17:08 UTC Modified: 2015-01-29 21:20 UTC
From: Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: master-Git-2015-01-29 (Git) OS: 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.
Block user comment
Status: Assign to:
Bug Type:
New email:
PHP Version: OS:


 [2015-01-29 17:08 UTC]
Using variables to reference object properties doesn't work in certain cases.

Test script:
$obj = new stdClass();
$obj->bar = "xyz";
$data = array("foo" => "bar");
$key = "foo";
echo $obj->$data[$key];
$member = $data[$key];
echo $obj->$member;

Expected result:

Actual result:
Notice: Array to string conversion in Command line code on line 1

Notice: Undefined property: stdClass::$Array in Command line code on line 1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-29 19:18 UTC] cmbecker69 at gmx dot de
This BC break is deliberately caused by the Uniform Variable Syntax
RFC[1], and as such is not a bug.

According to <> the offending
statement is

  echo $obj->$data[$key];
which is now interpreted as

  echo ($obj->$data)[$key];

[1] <>
 [2015-01-29 19:23 UTC]
-Status: Open +Status: Not a bug
 [2015-01-29 19:23 UTC]
echo $obj->{$data[$key]};
 [2015-01-29 21:20 UTC]
Small issue with {}

It's not too important, but I'll ask opinions on the internal list.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Mar 03 13:01:28 2024 UTC