Question

If I set

$myVar = "yay";
die($myVar);

that echos out yay, and kills the script.

However, if I set

$myVar = 2;
die($myVar);

nothing echos.

Why is that?

Cheers guys.

Was it helpful?

Solution 2

If you really want to print an integer then simply cast it as a string

<?php
  $var = 1;
  # exit() or die()
  exit("".$var);
?>

OTHER TIPS

Directly from the PHP Manual, die() is the same as exit(), and exit($status) says this:

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top