PHP
downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

eval> <defined
Last updated: Fri, 14 Aug 2009

view this page in

die

(PHP 4, PHP 5)

dieAlias de la fonction exit()

Description

Ce constructeur de langage est équivalent à exit().



eval> <defined
Last updated: Fri, 14 Aug 2009
 
add a note add a note User Contributed Notes
die
Damien Bezborodov
21-Aug-2009 05:45
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:

<?php
fwrite
(STDERR, "An error occurred.\n");
exit(
1); // A response code other than 0 is a failure
?>

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.
watch dot do dot sun at gmail dot com
19-Aug-2009 01:55
You can use this function for mysql connection.

For example:

<?php

$conn
= mysql_connection("localhost","root",12345678);

if(!
$conn){
die(
"Couldn't connected mysql");
}

?>

So if you can't connect to mysql you will take the message.
ecziegler at gmail.com
12-May-2008 01:06
If you are using auto append file (auto_append_file ="_end.php";) on your php.ini, be carefull on using die anywhere you want your appended file to be called. Souds obvious now but took me a good 1 hour to realise why one script was not appending end file as expected.

I solved using `return` instead; it works anywhere not just inside functions and the effect is pretty much the same as die.
jbailey at raspberryginger dot com
20-Jan-2007 05:33
die doesn't prevent destructors from being run, so the script doesn't exit immediately, it still goes through cleanup routines.
28-Sep-2004 04:36
Perhaps the Coldfusion query below can be answered as follows:
---------
(From the "User Contributed Notes" for the PHP construct "exit")

nospam at mydomain dot com
27-Sep-2004 10:12
Using return instead of exit is to prefer when you want the script that you have included inside another script to die but continue to execute the main script.
// Radcliff
---------
matthias dot schniedermeyer at telefonica dot de
14-Oct-2003 02:29
To get a perl-like die you can/should append this snipped
 . " File: " . __FILE__ . " on line: " . __LINE__
e.g.
die ("Error" . " File: " . __FILE__ . " on line: " . __LINE__);

eval> <defined
Last updated: Fri, 14 Aug 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites