Often see this statement: $file = fopen ($filename, ' r ') or Die ("Sorry, unable to open: $filename");
Or is understood here, because the data type is not differentiated in PHP, so the $file can be either int or bool, so the statement does not get an error. But the process may be some friends are not very clear. In most languages, in a statement such as BOOL or bool, a value is no longer judged if the previous value is true. This is also the case, so if the fopen function executes correctly, it returns an int value greater than 0 (which is actually "true"), and the subsequent statement will not be executed. If the fopen function fails, it will return false, then it will determine if the subsequent expression is true. The result is that after the die () is executed, no matter what is returned, the program has stopped executing, and the specified error message is displayed, and the purpose of debugging is achieved. That's it. :)
The two functions commonly used with error management are Die () and exit () (strictly speaking, they are language constructs, not functions, but who cares about them). When Die () and exit () are called in the script, the entire script is terminated. They can all be used to prevent the script from continuing, leaving some important operations, such as establishing a database connection, from occurring. You can also pass a string that will be printed in the browser to Die () and exit ().
You can usually see the use of Die () and exit () in an or conditional statement. For example
Include (' config.inc.php ') OR die (' Could not open the file. ');
After containing such a line of code, if PHP cannot contain the configuration file, the die () statement will be executed and the could not open the file message will be printed.
!defined (' Curscript ') && define (' Curscript ', ");//means that if you do not define a Curscript constant, the definition curscript is empty.
In the book and in the PHP manual, you will see a variety of variants, as it is a shortcut to handling errors (but possibly excessive) without using a custom error handler.
In fact, die and exit are equivalent, used to terminate the current script!