PHP: die - Manual
[/] Downloads Documentation Get Involved Help Getting Started Introduction A simple tutorial Language Reference Basic syntax Types Variables Constants Expressions Operators Control Structures Functions Classes and Objects Namespaces Errors Exceptions Generators References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Context options and parameters Supported Protocols and Wrappers Security Introduction General considerations Installed as CGI binary Installed as an Apache module Filesystem Security Database Security Error Reporting Using Register Globals User Submitted Data Magic Quotes Hiding PHP Keeping Current Features HTTP authentication with PHP Cookies Sessions Dealing with XForms Handling file uploads Using remote files Connection handling Persistent Database Connections Safe Mode Command line usage Garbage Collection DTrace Dynamic Tracing Function Reference Affecting PHP's Behaviour Audio Formats Manipulation Authentication Services Command Line Specific Extensions Compression and Archive Extensions Credit Card Processing Cryptography Extensions Database Extensions Date and Time Related Extensions File System Related Extensions Human Language and Character Encoding Support Image Processing and Generation Mail Related Extensions Mathematical Extensions Non-Text MIME Output Process Control Extensions Other Basic Extensions Other Services Search Engine Extensions Server Specific Extensions Session Extensions Text Processing Variable and Type Related Extensions Web Services Windows Only Extensions XML Manipulation Keyboard Shortcuts ? This help j Next menu item k Previous menu item g p Previous man page g n Next man page G Scroll to bottom g g Scroll to top g h Goto homepage g s Goto search (current page) / Focus search box eval » « defined PHP Manual Function Reference Other Basic Extensions Misc. Misc. Functions Change language: English Brazilian Portuguese Chinese (Simplified) French German Japanese Korean Romanian Russian Spanish Turkish Other Edit Report a Bug die (PHP 4, PHP 5) die — Equivalent to exit Description This language construct is equivalent to exit() . add a note User Contributed Notes 3 notes up down 151 Hayley Watson ¶ 3 years ago It is poor design to rely on die() for error handling in a web site because it results in an ugly experience for site users: a broken page and - if they're lucky - an error message that is no help to them at all. As far as they are concerned, when the page breaks, the whole site might as well be broken. If you ever want the public to use your site, always design it to handle errors in a way that will allow them to continue using it if possible. If it's not possible and the site really is broken, make sure that you find out so that you can fix it. die() by itself won't do either. If a supermarket freezer breaks down, a customer who wanted to buy a tub of ice cream doesn't expect to be kicked out of the building. up down 35 Damien Bezborodov ¶ 6 years ago Beware that when using PHP on the command line, die("Error") simply prints "Error" to STDOUT and terminates the program with a normal exit code of 0. If you are looking to follow UNIX conventions for CLI programs, you may consider the following: In this way, when you pipe STDOUT to a file, you may see error messages in the console and BASH scripts can test for a response code of 0 for success: rc@adl-dev-01:~$ php die.php > test An error occurred. rc@adl-dev-01:~$ echo $? 1 Ideally, PHP would write all Warnings, Fatal Errors, etc on STDERR, but that's another story. up down 25 jbailey at raspberryginger dot com ¶ 8 years ago die doesn't prevent destructors from being run, so the script doesn't exit immediately, it still goes through cleanup routines. add a note Misc. Functions connection_aborted connection_status constant define defined die eval exit get_browser __halt_compiler highlight_file highlight_string ignore_user_abort pack php_check_syntax php_strip_whitespace show_source sleep sys_getloadavg time_nanosleep time_sleep_until uniqid unpack usleep Copyright © 2001-2015 The PHP Group My PHP.net Contact Other PHP.net sites Mirror sites Privacy policy