exit, die, and return

Like break, the exit statement offers a way to escape from execution, but the exit statement stops all execution. Not even text outside of PHP tags is sent to the browser. This is useful when an error occurs and it would be more harmful to continue executing code than to just abort. This is often the case when preparing database queries. If the SQL statement cannot be parsed, it makes no sense to try to execute it.

The die statement is similar to exit, except that it may be followed by an expression that will be sent to the browser just before aborting the script. Using the fact that subexpressions in an if statement are evaluated left to right and only as necessary, the idiom in Listing 3.11 is allowed. Notice the parentheses ...

Get Core PHP Programming: Using PHP to Build Dynamic Web Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.