O'Reilly logo

Core PHP Programming: Using PHP to Build Dynamic Web Sites by Leon Atkinson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required