In PHP and some other scripting languages have the $var
syntax while Java and other languages we can do just var
.
Is there any theory behind it? Does it help them to parse. If not why would they choose to tack on an extra character in front?
An ampersand just before the function name will return a reference to the variable instead of returning its value.
Rules for PHP variables: A variable starts with the $ sign, followed by the name of the variable. A variable name must start with a letter or the underscore character. A variable name cannot start with a number.
Rasmus Lerdorf, the father of the PHP language, explains the $ sign as an ability to insert variables inside literal string values (interpolation), so that the variables are distinguished from the rest of the string.
Compatible with several OS and platform In addition, the programming language's interface is perfect with MySQL and Apache servers. Thus, it covers all major operating systems existing in various platforms. Likewise, PHP is also great for creating cross-platform web applications.
It prevents variable names conflicting with language keywords, and allows them to be interpolated in strings.
My theory is that scripting languages such as php would need some way to continue to run even if a new reserved word is introduced, such as php4 -> php5 got catch added. Since its a scripting language any webpages that had catch as a variable name would not die, due to the change in the language.
This is not an issue with compiled languages since everything is converted to a binary and any changes in the language would not affect already compiled programs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With