https://stackoverflow.com/a/3073818
but because early PHP was more simplistic than Perl it only has $.
Powershell also uses $ for variables.
Regardless of etymology of the $ sign and the usefulness of it, personally I like it because it makes it easier for me when I'm reading code, especially if you are scanning fast, to differentiate variables from symbols. Yes, you can get that with your editor too, but for me it is easier to associate the $ sign with a variable rather than a specific color, sometimes you don't have coloring available like when in command line going thru diffs, cat, nano etc.
$foo = "I am foo\n";
$bar = "foo";
echo $$bar;
This is in the documentation under "variable variables" [0]. This also lets you create dynamic function names: function run_foo() {
echo "I'm a foo\n";
}
$method = 'foo';
$picked = "run_$method";
$picked();
[0] https://www.php.net/manual/en/language.variables.variable.ph...Plus, to have different scoping rules was considered a good idea? Weird scoping issues were why I gave up on Ruby fifteen years ago; perhaps it was a good idea that I got never that far with PHP. But I'm intrigued now; what exactly are the scoping differences in question?
I didn't say it's necessary for the parser, but it's useful for the learner/user.
$strlen = 'strlen';
echo $strlen('test');
I’ve also seen things like this:
$return = ...
You can’t use a keyword as a variable in most other languages.
You can get used to that in 10 min and move on with your life, it is not a reason to not pick up the language, it's bike shedding.
At the very least it seems nonsensical and cargo-cultish: As a non PHP-er, what is the actual purpose of $? In Perl, it indicates variable context (for better or worse, there's more than one, so it has to be indicated somehow). In shell, it indicates the substitution of variable name by its value. In PHP...I draw a blank. It really seems like an "I wanted my language to look like some other language but I had no idea what it should be doing" kind of thing.