Last Updated: February 25, 2016
·
819
· fredylg

Debugging with Die() not always works

Well I found this issue that if you are not aware of may cause you trouble while debugging code.
If you try to print a variable within a method by 'die()-ing' on it , it wont print anything if is not "stringed" eg:

**** THIS WONT PRINT ANYTHING *****
Class protip{
function Eg(){
$now = time();
die($now);
}
}

$class = new protip;
$class->Eg();

**** THIS WILL *****
Class protip{
function Eg(){
$now = time();
die(' '.$now); //I know is not a nice way of doing it ,
// you can also go like (string)
}
}
$class = new protip;
$class->Eg();

Any comments? let me know , happy to discuss

1 Response
Add your response

die is an alias of exit()

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

void exit ([ string $status ] )

void exit ( int $status )

If status is a string, this function prints the status just before exiting.

If status is an integer, that value will be used as the exit status and not printed. Exit statuses should be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used. The status 0 is used to terminate the program successfully.

over 1 year ago ·