Answer the question
In order to leave comments, you need to log in
Is $ operator in php?
I'm developing a PHP parser and I've come across such an ambiguous question.
As you know, the official language specification simply does not exist. At the office website, there is no $ sign in the operations priority table .
Nevertheless, expressions of the form
<?php
function testMe($a) {
//do something
}
$func = 'testMe';
$func(21);
<?php
$myVar = 14;
$t = 'myVar';
$$t += 1;
echo $myVar;
Answer the question
In order to leave comments, you need to log in
Have you tried to look in the sources of the Zend PHP parser?
Maybe there is a more accurate answer.
Not an operator.
As for the syntax, it is sometimes curious to look into ru2.php.net/manual/en/tokens.php
It seems that not only constructs like $$var are valid, but also more complex ones. For example, the following code outputs 1111.
<?php
$a=1;
echo $a;
$b="a";
echo $$b;
$c="b";
echo $$$c;
$d="c";
echo $$$$d;
?>
en.php.net/manual/en/language.variables.basics.php
en.php.net/manual/en/language.variables.variable.php
This is not an operator, this is the “beginning” of a variable, and also constructions like $$ mean (roughly speaking) a variable in the variable name and were provided by the creator of the language initially, just like {} - it tritely selects a variable from a string, although it works without strings .
Although it is close in function to the pointer dereference operator, it cannot be considered an operator. Just an element of variable name syntax.
The operator does something.
For example echo outputs, require includes.
$ and $$ simply show the interpreter how to deal with this or that variable.
BUT
www.php.net/manual/en/language.operators.php
The variable symbol '$' should be considered as the highest-precedence operator, so that the variable variables such as $$a[0] won't confuse the parser.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question