note 108660 added to function.set-error-handler

From: Date: Tue, 15 May 2012 20:44:36 +0000
Subject: note 108660 added to function.set-error-handler
Groups: php.notes 
Request: Send a blank email to php-notes+get-187994@lists.php.net to get a copy of this message
<?php // Assume this function definition: function foo($bar, $baz = 'qux') { return $bar.$baz; } // Oh crap, something went wrong, and we call it without arguments: $foo = foo(); // Produces: // PHP Warning: Missing argument 1 for foo() bla bla bla // PHP Notice: Undefined variable: bar in bla bla bla // And script doesn't terminate. That's really stupid. // Here is a simple solution: set_error_handler(function($errno, $errstr) { if (preg_match('/Missing argument/', $errstr)==1) trigger_error('Bad luck! Missing argument causes fatal error', E_USER_ERROR); }, E_WARNING); $foo = foo(); // PHP Fatal error: Bad luck! Missing argument causes fatal error in bla bla bla ?> ---- Server IP: 69.147.83.197 Probable Submitter: 178.252.78.184 ---- Manual Page -- http://www.php.net/manual/en/function.set-error-handler.php Edit -- https://master.php.net/note/edit/108660 Del: integrated -- https://master.php.net/note/delete/108660/integrated Del: useless -- https://master.php.net/note/delete/108660/useless Del: bad code -- https://master.php.net/note/delete/108660/bad+code Del: spam -- https://master.php.net/note/delete/108660/spam Del: non-english -- https://master.php.net/note/delete/108660/non-english Del: in docs -- https://master.php.net/note/delete/108660/in+docs Del: other reasons-- https://master.php.net/note/delete/108660 Reject -- https://master.php.net/note/reject/108660 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#187994) next »