Reputation: 4601
since echo is not a function, we do not use parenthesis when calling it.
example:
echo "hello";
as opposed to
echo ("hello");
If it were to be a function, it would have been forced to be called as echo ("hello");
In ASP/Vbscript, I can call a function one of the following ways;
call dosomething("x","y","z")
dosomething "x","y","z" notice the missing parathesis
The closest thing I have seen to this parenthesis-free syntax in PHP is the echo. I like the ability to skip the parenthesis.
My question to you is if there is a way to write a function in PHP, that would not require the use of the parenthesis?
Upvotes: 4
Views: 6402
Reputation: 19
echo() is not actually a function (it is a language construct), so you are not required to use parentheses with it.
More about echo can be found here: http://php.net/manual/en/function.echo.php
Upvotes: 0
Reputation: 490343
From within PHP? No.
You'd need to modify the C code in the Zend Engine. This is of course undesirable as you would need to use a custom build to run your code. It would also be confusing needlessly to other programmers. You should not try to change core language features simply because you like the ability to skip tokens.
The parenthesis are important to denote function invocation.
Things such as echo
, include
, etc are called language constructs. The way they are implemented in the language are similar to normal unary operators such as new
, ++
etc.
Note too that language constructs do not strictly omit the parenthesis. Take unset()
for example.
Upvotes: 12
Reputation: 3412
no. "Echo" is not a function in php, but a language construct, that's why you can use it without parens. The same goes for "include" or "require", you can use them with or without parens.
Upvotes: 2