note 64522 added to function.set-error-handler

From: Date: Mon, 17 Apr 2006 16:50:52 +0000
Subject: note 64522 added to function.set-error-handler
Groups: php.notes 
Request: Send a blank email to php-notes+get-108350@lists.php.net to get a copy of this message
making use of a class based errorhandler is much better as it allows you to store filepointers inside the class or keep a record of error wich have been handled since in an array. but the problem is that php support class based error handlers since php4.3 but here's a very simple workaround that works in all version of php. <?php function myerrorhandler($errno, $errstr, $errfile, $errline, errcontext){ static $cp; // this is where we store the class //check to see if cp already contains our class. if((is_object($cp)) AND (get_class($cp) == "myclass")){ }else{ // class does not alreay exists so create it. $cp = new myclass(); } // then call our class based error handler return $cp->handler($errno, $errstr, $errfile, $errline, $errcontext); } ?> now register your errorhandler like this: set_errorhandler("myerrorhandler"); wich is the same as: set_errorhandler(array($myclass, "handler")); and this simple workaround works in all php versions. ---- Server IP: 66.163.161.117 Probable Submitter: 62.216.10.14 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.set-error-handler.php Edit -- http://master.php.net/note/edit/64522 Del: integrated -- http://master.php.net/note/delete/64522/integrated Del: useless -- http://master.php.net/note/delete/64522/useless Del: bad code -- http://master.php.net/note/delete/64522/bad+code Del: spam -- http://master.php.net/note/delete/64522/spam Del: non-english -- http://master.php.net/note/delete/64522/non-english Del: in docs -- http://master.php.net/note/delete/64522/in+docs Del: other reasons-- http://master.php.net/note/delete/64522 Reject -- http://master.php.net/note/reject/64522 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#108350) next »