php.net |  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: yunosh@php.net 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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: yunosh@php.net
New email:
PHP Version: OS:

 

 [2015-01-29 17:08 UTC] yunosh@php.net
Description:
------------
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:
----------------
xyzxyz

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
xyz

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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 <http://3v4l.org/TOH3G#vphp7@20140901> the offending
statement is

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

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

[1] <https://wiki.php.net/rfc/uniform_variable_syntax>
 [2015-01-29 19:23 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2015-01-29 19:23 UTC] requinix@php.net
echo $obj->{$data[$key]};
 [2015-01-29 21:20 UTC] yohgaki@php.net
Small issue with {}

http://3v4l.org/rouns

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