note 63910 added to function.trigger-error

From: Date: Mon, 03 Apr 2006 16:28:24 +0000
Subject: note 63910 added to function.trigger-error
Groups: php.notes 
Request: Send a blank email to php-notes+get-107235@lists.php.net to get a copy of this message
Beware, trigger_error() is absolutely useless for transporting your own function's error messages in $php_errormsg: ini_set('track_errors', TRUE); function x() { trigger_error('MY ERROR'); } @x(); echo "Error 1: \\"$php_errormsg\\"\\n"; @file_get_contents('/nonexisting'); echo "Error 2: \\"$php_errormsg\\"\\n"; This outputs: Error 1: "" Error 2: "failed to open stream: No such file or directory" This behaviour is consistent with the description of $php_errormsg, which says that the variable will only be available within the scope in which the error occurred. The problem can be worked around with a custom error handler like the one below. However, I'm undecided whether changing the language in this way is good: function errHandler($errno, $errstr, $errfile, $errline) { global $php_errormsg; $php_errormsg = $errstr; } set_error_handler('errHandler'); ---- Server IP: 66.163.161.117 Probable Submitter: 141.84.8.80 ---- 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.trigger-error.php Edit -- http://master.php.net/note/edit/63910 Del: integrated -- http://master.php.net/note/delete/63910/integrated Del: useless -- http://master.php.net/note/delete/63910/useless Del: bad code -- http://master.php.net/note/delete/63910/bad+code Del: spam -- http://master.php.net/note/delete/63910/spam Del: non-english -- http://master.php.net/note/delete/63910/non-english Del: in docs -- http://master.php.net/note/delete/63910/in+docs Del: other reasons-- http://master.php.net/note/delete/63910 Reject -- http://master.php.net/note/reject/63910 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#107235) next »