Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does "exit" require parentheses?

Tags:

php

If echo can work withouth the parentheses why exit can't?

like image 681
Emanuil Rusev Avatar asked Sep 29 '10 08:09

Emanuil Rusev


1 Answers

They're both language constructs (T_ECHO and T_EXIT), but different kinds. You can use exit without parentheses, but not if you're passing a value. Another quirk is that echo requires you not to use parentheses if you pass more than one value:

php > echo 'foo', 'bar';
foobar
php > echo ('foo', 'bar');
PHP Parse error:  syntax error, unexpected ',' in php shell code on line 1

If you're now thinking, "But that doesn't really explain why the design is inconsistent", welcome to PHP.

like image 97
Matthew Flaschen Avatar answered Oct 05 '22 19:10

Matthew Flaschen