Why the print and echo functions do not require parentheses around them

Just wondering.

Thanks.

And I just put it so that it reaches 30 characters, ignore this bit :)

+4
source share
2 answers

Because they are PHP structures (also called constructs), not functions

+7
source

echo is not really a function, it is a language construct, so you do not need to use parentheses with it. echo, unlike some other language constructs, does not behave like a function, so it cannot always be used in the context of a function.

Since echo does not behave like a function, the following code is invalid.

($some_var) ? echo 'true' : echo 'false'; 

However, the following examples will work:

 ($some_var) ? print 'true' : print 'false'; 

print is also a construct, but it behaves like a function, so it can be used in this context.

0
source

All Articles