We may be able to generate a user warning with Trigger_Error () to make the program more flexible. INDEX2.PHP
php // php 4 Require_once ('cmd_php4 / command.php'); Class CommandManager {var $ cmddir = "cmd_php4"; function getcommandObject ($ cmd) {$ PATH = "{$ this-> cmddir} / {$ CMD} .php "; if (! File_exists ($ PATH)) {Trigger_ERROR (" Cannot Find $ PATH ", E_USER_ERROR);} Require_once $ path; if (! Class_exists ($ cmd)) {Trigger_ERROR (" Class $ cmd does NOT EXIST ", E_USER_ERROR);} $ RET = New $ cmd (); if (! is_A ($ RET, 'Command')) {Trigger_ERROR (" $ cmd is not a command ", e_user_error);} Return $ Ret; }}?>
If you use the Trigger_Error () function to replace Die (), your code will be more advantageous in handling errors, which is more easier to handle errors for customer programmers. Trigger_ERROR () accepts an error message and a constant as a parameter. Constants are:
Constant Meaning E_USER_ERROR A FATAL ERROR E_USER_WARNING A NON-FATAL ERROR E_USER_NOURE A Report That May Not Repesent An Error
You can design an error handler, then define a processor selection function set_error_handler () to use this error handler. Index2.php second half of the half PHP
// PHP 4
Function Cmderrorhandler ($ Errnum, $ Errmsg, $ FILE, $ LINENO) {
IF
$ Errnum == E_USER_ERROR) {
"Error: $ Errmsg / N";
File: $ file / n ";
"Line: $ LINENO / N";
Exit ();}}
$ HANDLER = set_error_handler ('cmderrorhandler');
$ mgr = new commandManager ();
$ cmd = $ mgr-> getcommandObject ('realcommand');
$ cmd-> execute ();
?>