Re: Use of {} with member.
| From: | Andrea Faulds | Date: | Thu, 29 Jan 2015 22:17:49 +0000 |
| Subject: | Re: Use of {} with member. | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-81391@lists.php.net to get a copy of this message | ||
Hi Yasuo,
> On 29 Jan 2015, at 22:14, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote:
>
> Hi Andrey,
>
> On Fri, Jan 30, 2015 at 6:43 AM, Andrey Andreev <narf@devilix.net> wrote:
>>
>> Is somebody actually recommending the latter form? I'm surprised that
>> it even works ... that should be a syntax error IMO.
>
>
> Do you mean
>
> echo "${array[$key]}"; // Works
>
> should be errror?
> This form is common in shell scripting.
>
> http://tldp.org/LDP/abs/html/parameter-substitution.html
>
> I'm using it regularly. I guess many users expect following forms to work.
>
> $obj->${array[$key]}; // Syntax error
> $obj->${key}; // E_NOTICE. Does not work
>
> What others expect?
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.
--
Andrea Faulds
http://ajf.me/