In PHP when you write a set a variable equal to a string wrapped in grave accents, it gets executed as it would if it were inside a shell_exec()
command. What does the grave accent symbol (`) ( not single quote) represent in PHP?
So, in php you can do all sorts of things to combine strings with variables, etc, what can I and can't I do when using ` instead of ' or " ?
In the PHP, that character is called a backtick operator.
A literal string wrapped in backticks is a
T_ENCAPSED_AND_WHITESPACE
token. You can confirm this by running something like this:which gives you this:
And then run
token_name(313)
which gives youT_ENCAPSED_AND_WHITESPACE
.To the parser, a string wrapped in backticks is equivalent to a string with variables in it like
"hello $world"
. The literal/constant part of the string (thehello
part) isT_ENCAPSED_AND_WHITESPACE
.So to answer your question, anything that you can do to a string that contains variables you can do to a string wrapped in backticks.
So why
T_ENCAPSED_AND_WHITESPACE
? Probably, because like a string containing variables, it's value is determined at runtime. Whereas aT_CONSTANT_ENCAPSED_STRING
(a normal literal string) is kind of like a constant in the eyes of the parser.