I wonder why php uses dollar sign near variables? Is there was some technical needs? Or just for better readability (looks like worse for me)? Or that is somehow related to interpreter logic?
Asked
Active
Viewed 513 times
-2
-
See http://stackoverflow.com/a/3073818/1012576 – vim Mar 02 '15 at 12:50
-
1Of course, the "English" version of PHP doesn't use a `$`, it uses a `£` instead – Mark Baker Mar 02 '15 at 12:52
-
... and the Australian version uses `AU$`, which must be a right pain to type! – halfer Mar 02 '15 at 13:19
-
[English version of PHP](https://www.addedbytes.com/blog/if-php-were-british/) – Mark Baker Mar 02 '15 at 13:49
1 Answers
-2
This is asked repeatedly. PHP is a on-demand parser. It needs to be very very fast. Therefore, having a $ to quickly indicate "here is a variable" makes parsing faster. Further, you can use a dollar sign in other languages because most consider the $ to be a valid character in variable names.
kainaw
- 4,256
- 1
- 18
- 38
-
I'm not a fan of it, but I see a lot of `$` variable names in JavaScript (aside from the jQuery usage). – halfer Mar 02 '15 at 13:19
-
It's also been answered often. And never was this the accepted answer: because it's just not the reason... – Jasper Mar 08 '20 at 17:55
-
If you REALLY want to get to the bottom of it, you need to talk to Ken Thompson. His goal was speed of line parsing. Using a $ made line parsing faster. That usage in the Thompson Shell continued through other shells, into Perl, and into PHP. – kainaw Mar 29 '21 at 19:39