Re: [PHP] Curio
- Original Message - From: "Richard Lynch" <[EMAIL PROTECTED]> 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
Re: [PHP] Curio
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. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Curio
At 11:31 AM +0100 6/10/06, 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? > I don't know why in they do it in php, but I would guess that it's one of those legacy things. Back when I was programming with rocks, a language called FORTRAN came along (before FORTRAN started having Roman Numerals after its name). The rules of this new language was that integers could only start with the letters I, J, K, L ,M, N (hence our custom to use $i , $j, $k for loops) and all other real number could start with any other character but those, and could not start numbers -- however, both variables could contain numbers but were limited to just six letters total. (But note we didn't have to start variables with a $ ). As far as strings were concerned -- what the hell were those? If you wanted to print something, you use a FORMAT statement and therein you might find syntax that could start with a number, such as 4F5.0, but that was just to format a number for print -- it had nothing to do with a variable name. In defense of the decision of the time, I doubt that many of you remember IBM punch cards (one card for every line of code in your program) but it was a *great* deal easier to review and edit your stack of code if you kept numbers and letters separate with different meanings. So, my guess is it's legacy. My question to you is, what are you passing on that in 40 years some young programmer will ask "Why is it illegal to..." :-) tedd -- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Curio
[snip] 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? [/snip] This is fairly standard in programming languages. Years ago (sometime in the 70's) the reasoning was given to me, but I have long since replaced the data at that address with some other, probably trivial, fact. I tried a quick Google, but no joy. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Curio
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? -- http://www.web-buddha.co.uk dynamic web programming from Reigate, Surrey UK (php, mysql, xhtml, css) look out for project karma, our new venture, coming soon!