die() function is error handling method in PHP which used to handle a error in web application. It's also used to check whether the function is work properly or not.
<?php
$file=fopen("myfile.txt","r");
?>
If myfile.txt file does not exist, you might get an error like this in your front end:
Warning: fopen(myfile.txt) [function.fopen]: failed to open stream. No such file or directory
die() function example:
<?php
if(!file_exists("myfile.txt")) {
die("File not found"); // here die() function remove the warning msg & print file not found..
} else {
$file=fopen("myfile.txt","r");
}
?>
0 Comment(s)