Hi,
On Fri, Jan 30, 2015 at 12:49 AM, Yasuo Ohgaki <[email protected]> wrote:
> Hi Andrea,
>
> On Fri, Jan 30, 2015 at 7:17 AM, Andrea Faulds <[email protected]> wrote:
>>
>> I would expect that anything within ${} works the same as it does outside
>> it. Having $obj->${array[$key]} do something different to $key =
>> array[$key], $obj->${$key} would make no sense to me.
>
>
> Good point! I forgot about variable variable.
> PHP works as follows now.
>
> http://3v4l.org/dpbES
>
> Andrey, the reason why you are surprised is probably because of this
> // echo "${obj->var}"; // Syntax error
>
Not entirely ... I just have it as a rule of thumb that if it's not
valid code with nothing around it, I shouldn't expect it to be valid
inside curly braces (excluding the semicolon of course). Pretty much
what Andrea said ...
<?php array['foo']; ?> is a syntax error, so I don't expect
${array['foo']} to be valid either. In fact, I just checked and it's
not: http://3v4l.org/B6kdv
echo "${array['foo']}"; probably works only because of how variables
are parsed inside double quotes.
Cheers,
Andrey.
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php