Pregunta

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.

¿Fue útil?

Solución 2

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

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

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top