Errors may arise in your PHP application due to unforeseen reasons. These errors can be caused by a variety of reasons. When PHP encounters these errors, it returns long, not so user-friendly error messages. To avoid this, you can take advantage of the PHP die()
function.
Take the example below where a variable is used but was not declared.
<?php
if ($x == "True") {
echo "True";
} else {
echo "<br>";
die('Variable $x is not declared.');
}
This gives additional information rather than just getting this:
> Warning: Undefined variable $x in main.php on line 3.