Re: ${0} variable basics
| From: | Domain nikha . org | Date: | Mon, 25 Aug 2014 19:51:33 +0000 |
| Subject: | Re: ${0} variable basics | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-323792@lists.php.net to get a copy of this message | ||
> Christoph Becker am Montag, 25. August 2014 - 16:25:
> Negin Nickparsa wrote:
> > why ${0} is valid but ${0 is not valid?
> > it means that curly braces evaluate what's inside them
>
> No, at least not in the general case. This notation is called "simple
> syntax" in the PHP manual[1] and "Variable-Name Creation
> Operator/Expression" in the current draft of the PHP language
> specification[2].
>
> > and that's why we
> > cannot have ${0?
> >
> > variables shouldn't start from 0 so it means that it started from braces?
> > if yes why I cannot have ${0? and what is the variable here finally? $0 is
> > what it interprets?
>
> Yes, indeed. However, the notation $0 would be a syntax error.
>
> > if yes so it is not a legal variable
>
> Well, actually it is a legal variable, but it might better be avoided to
> use such variables. They are confusing, and I can't think of any
> advantage in using such variables. Use $zero instead, or maybe an array.
>
> > I am totally mixed up.
>
> [1]
>
> <http://php.net/manual/en/language.types.string.php#language.types.string..parsing.simple>
> [2]
>
> <https://github.com/php/php-langspec/blob/master/spec/10-expressions.md#user-content-variable-name-creation-operator>
>
> --
> Christoph M. Becker
>
The manual is not realy clear in this point. My practical expierence says this:
an expression like "${....}" is always evaluated as string. ${0} creates a variable named
"0", because "0" is not the integer, that would be illegal.
And BTW: ${0000.578} gives you "0000_578", because dots in variable names are not allowed
and automatically converted to underscores. And it is NOT evaluated to a float.
Confusing, and indeed avoid it! Why the hell you really need a variable named "0"?
The fabulous type juggling of PHP operates on the values, not the names of variables!
--
Niklaus