Re: Curio

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



----- Original Message ----- From: "Richard Lynch" <ceo@xxxxxxxxx>


On Sat, June 10, 2006 5:31 am, Dave Goodchild wrote:
Just a question out of curiousity for the language lawyers out there.
Why is
it illegal to begin a variable name with a number in php?

Because Rasmus wrote that bit on a Tuesday. :-)

It's a pretty common requirement, actually.

--

I guess that most current parsers would easily handle variable names starting with numbers, not just in PHP, though it might be confusing to users. Floats with an exponent part (separated by an E or, in some cases, a D) might be confused for variable names. In some languages, numeric constants might have a suffix indicating the storage type (i.e: and L for long, or F for float) so there would be many rules of what is ok and what is not. Simple rules with few exceptions prevents silly user mistakes.

Now, as for PHP, with variable names always preceded by $, we are actually dealing with the second character, but not always, we have constructs such as $abc, ${abc}, {$abc} and finally $$abc, the first three refering to the very same variable, the last one to the variable named in $abc. In some of these cases there are symbols in between the $ and the variable name so it is not so simple as saying that the $ is the first character and and the 'a' (in these examples) is the second.

Then, there is the problem of heritage. Many of PHP features are based on *nix shells, such as BASH where $1, $2, .... have special meaning, but this does not apply to PHP.

So I guess the answer to the question of why is simply because it's the immemorial custom of the trade. And I admit I never thought of doing otherwise.

Satyam
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux