4

Just wondering.

Thanks.

And I'm just putting this so I can reach the 30 characters, ignore this bit :)

RedRocker227
  • 175
  • 1
  • 3
  • 6
  • possible duplicate of [Reference: Comparing PHP's print and echo](http://stackoverflow.com/questions/7094118/reference-comparing-phps-print-and-echo) – jensgram Aug 06 '12 at 10:50
  • 4
    They are not functions, they are *language constructs* and therein lies your answer. Unfortunately due to various bits and pieces of design stupidity over the years, the lack of requirement for parenthesis is not true of all language constructs. Some good further reading on the subject can be found [here](http://stackoverflow.com/questions/1180184/what-is-the-difference-between-a-language-construct-and-a-built-in-function-in) – DaveRandom Aug 06 '12 at 10:51

2 Answers2

7

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

Oussama Jilal
  • 7,669
  • 2
  • 30
  • 53
0

echo is not actually a function it is a language construct, so you are not required 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.

Because 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 may be used in this context.

Biswadeep Sarkar
  • 841
  • 9
  • 17