cvs: ZendEngine2 / zend_builtin_functions.c /tests bug38047.phpt
| From: | Dmitry Stogov | Date: | Thu, 27 Jul 2006 08:20:52 +0000 |
| Subject: | cvs: ZendEngine2 / zend_builtin_functions.c /tests bug38047.phpt | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-5137@lists.php.net to get a copy of this message | ||
dmitry Thu Jul 27 08:20:52 2006 UTC
Modified files:
/ZendEngine2 zend_builtin_functions.c
/ZendEngine2/tests bug38047.phpt
Log:
Fixed bug #38047 ("file" and "line" sometimes not set in backtrace from inside
error handler)
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_builtin_functions.c?r1=1.321&r2=1.322&diff_format=u
Index: ZendEngine2/zend_builtin_functions.c
diff -u ZendEngine2/zend_builtin_functions.c:1.321 ZendEngine2/zend_builtin_functions.c:1.322
--- ZendEngine2/zend_builtin_functions.c:1.321 Mon Jul 24 17:51:41 2006
+++ ZendEngine2/zend_builtin_functions.c Thu Jul 27 08:20:52 2006
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_builtin_functions.c,v 1.321 2006/07/24 17:51:41 helly Exp $ */
+/* $Id: zend_builtin_functions.c,v 1.322 2006/07/27 08:20:52 dmitry Exp $ */
#include "zend.h"
#include "zend_API.h"
@@ -1935,7 +1935,23 @@
if (filename) {
zend_printf(") called at [%s:%d]\n", filename, lineno);
} else {
- ZEND_PUTS(")\n");
+ zend_execute_data *prev = skip->prev_execute_data;
+
+ while (prev) {
+ if (prev->function_state.function &&
+ prev->function_state.function->common.type != ZEND_USER_FUNCTION) {
+ prev = NULL;
+ break;
+ }
+ if (prev->op_array) {
+ zend_printf(") called at [%s:%d]\n", prev->op_array->filename,
prev->opline->lineno);
+ break;
+ }
+ prev = prev->prev_execute_data;
+ }
+ if (!prev) {
+ ZEND_PUTS(")\n");
+ }
}
include_filename = filename;
ptr = skip->prev_execute_data;
@@ -2029,6 +2045,20 @@
* and debug_baktrace() might have been called by the error_handler. in this case we don't
* want to pop anything of the argument-stack */
} else {
+ zend_execute_data *prev = skip->prev_execute_data;
+
+ while (prev) {
+ if (prev->function_state.function &&
+ prev->function_state.function->common.type != ZEND_USER_FUNCTION) {
+ break;
+ }
+ if (prev->op_array) {
+ add_assoc_string_ex(stack_frame, "file", sizeof("file"),
prev->op_array->filename, 1);
+ add_assoc_long_ex(stack_frame, "line", sizeof("line"),
prev->opline->lineno);
+ break;
+ }
+ prev = prev->prev_execute_data;
+ }
filename = NULL;
}
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/bug38047.phpt?r1=1.1&r2=1.2&diff_format=u
Index: ZendEngine2/tests/bug38047.phpt
diff -u /dev/null ZendEngine2/tests/bug38047.phpt:1.2
--- /dev/null Thu Jul 27 08:20:52 2006
+++ ZendEngine2/tests/bug38047.phpt Thu Jul 27 08:20:52 2006
@@ -0,0 +1,50 @@
+--TEST--
+Bug #38047 ("file" and "line" sometimes not set in backtrace from inside error
handler)
+--FILE--
+<?php
+error_reporting(E_ALL);
+set_error_handler('kalus_error_handler');
+ini_set("display_errors", "on");
+
+class A {
+ function A_ftk($a) {
+ }
+}
+
+function kalus_error_handler($error_code, $error_string, $filename, $line, $symbols) {
+ echo "$error_string\n";
+ get_error_context();
+}
+
+function get_error_context() {
+ $backtrace = debug_backtrace();
+ $n = 1;
+ foreach ($backtrace as $call) {
+ echo $n++." ";
+ if (isset($call["file"])) {
+ echo $call["file"];
+ if (isset($call["line"])) {
+ echo ":".$call["line"];
+ }
+ }
+ if (isset($call["function"])) {
+ echo " ".$call["function"]."()";
+ }
+ echo "\n";
+ }
+ echo "\n";
+}
+
+//This will not create file and line items for the call into the error handler
+$page["name"] = A::A_ftk();
+?>
+--EXPECTF--
+Non-static method A::A_ftk() should not be called statically
+1 %sbug38047.php:13 get_error_context()
+2 %sbug38047.php:36 kalus_error_handler()
+3 %sbug38047.php:36 A_ftk()
+
+Missing argument 1 for A::A_ftk(), called in %sbug38047.php on line 36 and defined
+1 %sbug38047.php:13 get_error_context()
+2 %sbug38047.php:7 kalus_error_handler()
+3 %sbug38047.php:36 A_ftk()