Is not the echo
that accepts parentheses, what happens is that everything that comes afterward of echo
with or without parentheses will be understood as values, for example one or more strings or values or variables that can be "printable")
So much so that echo
supports multiple values, for example:
echo 'a', 'b', 'c';
or:
echo ('a'), ('b'), ('c');
If I did that I would fail:
echo ('a', 'b', 'c');
Causing the error:
Parse error: syntax error, Unexpected ','
It works this way because echo
is not a function, but rather a language builder.
I find that term a little strange, according to the documentation, but I understand that this means that the echo
is something "natural" in the PHP language, as if it were if
, else
, break
, etc. That is to say echo
is part of the language and behaves as needed and cannot actually be executed as a function.
Now understanding parentheses, in PHP (and even in most languages) they are used to "isolate" certain operations, like a mathematical operation in PHP so would return a value:
$foo = 20 + 8 * 2; // 36
echo $foo;
That would be another:
$foo = (20 + 8) * 2; // 56
echo $foo;
Namely the echo
or even set a variable ($foo =
) do not see the parentheses, the language itself evaluates this before and the parentheses are used to separate necessary operations, such as mathematical operations
In short, do it echo ('foo');
would almost be equivalent to doing this:
$a = ('foo');
echo $a;
For parentheses are not part of echo.