|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 19:00:01 2025 UTC |
echo $obj->{$data[$key]};Small issue with {} http://3v4l.org/rouns It's not too important, but I'll ask opinions on the internal list.