php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #30541 $php_errormsg isn't set when an error occured in a function called by eval()
Submitted: 2004-10-23 16:49 UTC Modified: 2016-02-19 12:14 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: php at dush dot student dot utwente dot nl Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 5.0.2 OS: linux 2.6
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php at dush dot student dot utwente dot nl
New email:
PHP Version: OS:

 

 [2004-10-23 16:49 UTC] php at dush dot student dot utwente dot nl
Description:
------------
in debug mode, my script stores every error that occured in the script. when an error occurs in eval(), the error is stored correctly in $php_errormsg. however when the error occured in a function called by eval() the error isn't stored anymore.

Reproduce code:
---------------
register_tick_function("store_errors", true);
function &store_errors($do_tick = true) {
	GLOBAL $php_errormsg;
	static $errors = array();
	if ($do_tick) {
		if (isset($php_errormsg) && $php_errormsg != "") {
			if ($trace = debug_backtrace()) {
				$func = $trace[1]['function'];
				if (isset($trace[1]['class']))
					$func = $trace[1]['class'].$trace[1]['type'].$func;
			}else {
				$func = 'unknown';
			}
			$errors[] = array(
				0 => $php_errormsg,
				1 => $func
			);
			$php_errormsg = "";
		}
	}else {
		return $errors;
	}
}
/* stupid test function */
	function blah() { echo $blah2; echo "error is set here: $php_errormsg<br>"; }
	eval ('echo $blah1; blah();');
	$ar = store_errors(false);
	while(list($key,$val) = each($ar)) {
		echo "{$key} => {$val[0]} in {$val[1]}<br>\n";
	}

Expected result:
----------------
Notice: Undefined variable: blah1 in /home/dush/public_html/core/loader.inc.php(28) : eval()'d code on line 1

Notice: Undefined variable: blah2 in /home/dush/public_html/core/loader.inc.php on line 27
error is set here: Undefined variable: blah2
0 => Undefined variable: blah1 in unknown
1 => Undefined variable: blah2 in blah

Actual result:
--------------
Notice: Undefined variable: blah1 in /home/dush/public_html/core/loader.inc.php(28) : eval()'d code on line 1

Notice: Undefined variable: blah2 in /home/dush/public_html/core/loader.inc.php on line 27
error is set here: Undefined variable: blah2
0 => Undefined variable: blah1 in unknown

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-04 13:43 UTC] tony2001@php.net
Can't find any errors here:
<?
eval('echo $blah;');
var_dump($php_errormsg);
echo $bla;
var_dump($php_errormsg);
?>
outputs:
---
Notice: Undefined variable: blah in /www/index.php(3) : eval()'d code on line 1
string(24) "Undefined variable: blah" 
Notice: Undefined variable: bla in /www/index.php on line 7
string(23) "Undefined variable: bla"
---
Check your code.
 [2004-11-06 22:38 UTC] php at dush dot student dot utwente dot nl
<?
function bla3() {
	echo $bla3;
	var_dump($php_errormsg);
}
echo $bla2;
var_dump($php_errormsg);
eval('echo $bla1;');
var_dump($php_errormsg);
eval('bla3();');
var_dump($php_errormsg);
?>
outputs:
Notice: Undefined variable: bla2 in /home/dush/public_html/test.php on line 8
string(25) "Undefined variable: bla2" 
Notice: Undefined variable: bla1 in /home/dush/public_html/test.php(10) : eval()'d code on line 1
string(25) "Undefined variable: bla1" 
Notice: Undefined variable: bla3 in /home/dush/public_html/test.php on line 5
string(25) "Undefined variable: bla3"
string(25) "Undefined variable: bla1" 

It's certainly not a bug if it's supposed to be a different $php_errormsg for every scope, but I thought it was a global variable.
If I'm not correct, please think of adding something like $global_php_errormsg, as it would be very handy for debugging purposes without having errors on possibly a lot of different positions on a page with error_reporting(E_ALL);
 [2004-11-07 02:11 UTC] php at dush dot student dot utwente dot nl
and sorry, forgot to notice, I know of set_error_handler() :-)
 [2016-02-19 12:14 UTC] nikic@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues
 [2016-02-19 12:14 UTC] nikic@php.net
$php_errormsg is indeed a local variable. The global variant is called error_get_last().
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 00:01:28 2024 UTC