tags:

views:

149

answers:

4
exit()

is valid,but

exit()
echo 1;

Will fail.

Why?

+1  A: 

The first is correct syntax , the later isn't. If more than one command is provided, they have to be separated via ;. echo 1 wouldn't be executed anyway.

Felix Kling
+13  A: 

The semicolon terminates a statement, although it's not required if it's the last statement.

Ignacio Vazquez-Abrams
… last statement in the PHP block.
Gumbo
The semicolon doesn't terminate a statement. It **separates** two of them. That's why you can omit the semicolon at the end of a script/block.
Eineki
A: 

This:

exit()

will work only if it is at the end

But

exit()
echo 1;

In this case it is not on the end.

Sarfraz
@Felix `exit` is always the last statement that runs but not usually the last statement in the file. It's kinda pointless exiting or dieing as the script is about to end normally
meouw
one extra word (file) made the mess out of it, sorry, corrected it, thanks all
Sarfraz
A: 

You can do exit(1); to set the status/severity of the reason for using it. Or you can use exit("1"); and it will print the string. The difference being that the first is an integer and the second is a string.

See: http://php.net/manual/en/function.exit.php

zamabe
*An Eiffel Tower is a threesome with two guys and a girl. The guys are high-fiving over the girl to make the Eiffel Tower shape.*
Lo'oris