Bug #68947 [Com]: BC break accessing object properties

From: Date: Thu, 29 Jan 2015 19:18:49 +0000
Subject: Bug #68947 [Com]: BC break accessing object properties
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190316@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68947&edit=1

 ID:                 68947
 Comment by:         cmbecker69 at gmx dot de
 Reported by:        yunosh@php.net
 Summary:            BC break accessing object properties
 Status:             Open
 Type:               Bug
 Package:            Class/Object related
 Operating System:   Linux
 PHP Version:        master-Git-2015-01-29 (Git)
 Block user comment: N
 Private report:     N

 New Comment:

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>


Previous Comments:
------------------------------------------------------------------------
[2015-01-29 17:08:32] 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


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=68947&edit=1


Thread (4 messages)

« previous php.bugs (#190316) next »