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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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: Sat Sep 21 00:01:27 2024 UTC