Edit report at http://bugs.php.net/bug.php?id=53750&edit=1
ID: 53750
Comment by: tuhin dot barua at gmail dot com
Reported by: tuhin dot barua at gmail dot com
Summary: dynamic variable name problem
Status: Bogus
Type: Bug
Package: Scripting Engine problem
Operating System: ubuntu
PHP Version: 5.2.17
Block user comment: N
Private report: N
New Comment:
ok.
but how about this one ?
lets say this is the object
FacebookApiException Object
(
[result:private] => Array
(
[error] => Array
(
[type] => OAuthException
[message] => Invalid OAuth access token.
)
)
[message:protected] => Invalid OAuth access token.
)
how do i access field something like 'message:protected' ?
$field = 'message:protected';
$object->$field // dont work in this case neither does
$object->{$field}
is that a bug?
this kinda problem i faced with google data api as well... google has
some field name like dc:date ... and i had to change it to dc_date
before i can access it.
Previous Comments:
------------------------------------------------------------------------
[2011-01-17 05:12:49] [email protected]
This is a simple operator associativity issue: $a->$arr[0] is actually
parsed as $a->{$arr[0]}, and since the first character of $arr is "a",
the last line in the test script ends up effectively being
print_r($a->a).
You can work around this by changing the last line of the script to:
print_r($a->{$arr}[0]);
------------------------------------------------------------------------
[2011-01-14 17:58:00] tuhin dot barua at gmail dot com
Description:
------------
example 1:
php > $a = new stdclass();
php > $a->arr = array(1,2,3);
php > $arr = 'arr';
php > print_r($a->$arr);
Array
(
[0] => 1
[1] => 2
[2] => 3
)
php > print_r($a->$arr[0]);
php >
example 2:
php > $arr = array(1,2,3);
php > $a = 'arr';
php > print_r($$a);
Array
(
[0] => 1
[1] => 2
[2] => 3
)
php > print_r($$a[0]);
arr
php > print_r($$a[1]);
php >
Test script:
---------------
$a = new stdclass();
$a->arr = array(1,2,3);
$arr = 'arr';
print_r($a->$arr);
print_r($a->$arr[0])
Expected result:
----------------
cant access array elements with a dynamic variable name.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53750&edit=1