function - PHP Error Handling - "missing argument for errorHandler" -
i'm trying setup error handling first time.
work , report errors if there one, reason shows errors of 'missing arguments' error handling function itself. please note error handling function in separate file , included index page, i'm not sure if that's problem :s
here error handling function
function errorhandler($errno, $errstr, $error_file, $error_line) { if(isset($errstr)) { # there error, display echo $errno." - ".$errstr." in ".$error_file." @ line ".$error_line."<br>"; } else { # there isn't error, nothing return false; } } // must tell php use above error handler. set_error_handler("errorhanlder");
here index page
<!-- # error handler --> <? if(errorhandler()) { ?> <section id="error-handler"> <?=errorhandler();?> </section> <? } ?>
here result in browser (bear in mind there no php error, error handler shouldn't outputting - can't understand
2 - missing argument 1 errorhandler(), called in index.php on line 20 , defined in inc/arcerror.fnc.php @ line 10 2 - missing argument 2 errorhandler(), called in index.php on line 20 , defined in inc/arcerror.fnc.php @ line 10 2 - missing argument 3 errorhandler(), called in index.php on line 20 , defined in inc/arcerror.fnc.php @ line 10 2 - missing argument 4 errorhandler(), called in index.php on line 20 , defined in inc/arcerror.fnc.php @ line 10
any idea's why php reporting missing arguments?
you calling function 0 argument...
<?=errorhandler();?>
why need call anyway?
and there several typos in code: replace "hanlder" "handler".
there's no need that:
if(isset($errstr)) {
your error-handling function automatically called when there error (and in case!). $errstr parameter of function, set when function gets executed.
new code:
function errorhandler($errno, $errstr, $error_file, $error_line) { # there error, display echo "<section id='error-handler'>$errno - $errstr in $error_file @ line $error_line</section><br>"; } // must tell php use above error handler. set_error_handler("errorhandler");
Comments
Post a Comment