]> granicus.if.org Git - php/commitdiff
Fixed bug #47320 ($php_errormsg out of scope in functions)
authorDmitry Stogov <dmitry@php.net>
Mon, 9 Feb 2009 09:20:35 +0000 (09:20 +0000)
committerDmitry Stogov <dmitry@php.net>
Mon, 9 Feb 2009 09:20:35 +0000 (09:20 +0000)
NEWS
Zend/tests/bug47320.phpt [new file with mode: 0644]
Zend/zend_execute_API.c
main/main.c

diff --git a/NEWS b/NEWS
index 18aae13b05ef97854c73a43b7dea99f934c42f41..ef89228a81b31b05df68df6d6e49a5892068107c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2009, PHP 5.3.0 Beta 2
+- Fixed bug #47320 ($php_errormsg out of scope in functions). (Dmitry)
 - Fixed bug #47265 (generating phar.phar failes because of safe_mode). (Greg)
 - Fixed bug #47229 (preg_quote() should escape the '-' char). (Nuno)
 - Fixed bug #47085 (rename() returns true even if the file in PHAR does not exist). (Greg)
diff --git a/Zend/tests/bug47320.phpt b/Zend/tests/bug47320.phpt
new file mode 100644 (file)
index 0000000..47db35e
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+Bug #47320 ($php_errormsg out of scope in functions)
+--INI--
+display_errors=0
+track_errors=1
+--FILE--
+<?php
+if (!@substr('no 2nd parameter')) {
+    echo '$php_errormsg in global: ' . $php_errormsg . "\n";
+}
+
+function foo() {
+    if (!@strpos('no 2nd parameter')) {
+        echo '$php_errormsg in function: ' . $php_errormsg . "\n";
+
+        echo '$GLOBALS[php_errormsg] in function: ' .
+                $GLOBALS['php_errormsg'] . "\n";
+    }
+}
+
+foo();
+?>
+--EXPECT--
+$php_errormsg in global: substr() expects at least 2 parameters, 1 given
+$php_errormsg in function: strpos() expects at least 2 parameters, 1 given
+$GLOBALS[php_errormsg] in function: substr() expects at least 2 parameters, 1 given
index 3bdfc5b6e0a8e75dc91ee12d4b94fbc8abc787b6..36240eefce5481ea8eb11211053b174255c4e475 100644 (file)
@@ -1631,15 +1631,15 @@ ZEND_API void zend_rebuild_symbol_table(TSRMLS_D) /* {{{ */
                        return;
                }
 
-               if (EG(symtable_cache_ptr)>=EG(symtable_cache)) {
-                       /*printf("Cache hit!  Reusing %x\n", symtable_cache[symtable_cache_ptr]);*/
-                       EG(active_symbol_table) = *(EG(symtable_cache_ptr)--);
-               } else {
-                       ALLOC_HASHTABLE(EG(active_symbol_table));
-                       zend_hash_init(EG(active_symbol_table), 0, NULL, ZVAL_PTR_DTOR, 0);
-                       /*printf("Cache miss!  Initialized %x\n", EG(active_symbol_table));*/
-               }
                if (ex && ex->op_array) {
+                       if (EG(symtable_cache_ptr)>=EG(symtable_cache)) {
+                               /*printf("Cache hit!  Reusing %x\n", symtable_cache[symtable_cache_ptr]);*/
+                               EG(active_symbol_table) = *(EG(symtable_cache_ptr)--);
+                       } else {
+                               ALLOC_HASHTABLE(EG(active_symbol_table));
+                               zend_hash_init(EG(active_symbol_table), 0, NULL, ZVAL_PTR_DTOR, 0);
+                               /*printf("Cache miss!  Initialized %x\n", EG(active_symbol_table));*/
+                       }
                        ex->symbol_table = EG(active_symbol_table);
 
                        if (ex->op_array->this_var != -1 &&
index 0687c90001b395f3a8b91387c1ba5a5b1f6d2034..d98aafe4fdddfefa3130903e729a2e578f5dad7d 100644 (file)
@@ -750,12 +750,17 @@ PHPAPI void php_verror(const char *docref, const char *params, int type, const c
                efree(docref_buf);
        }
 
-       if (PG(track_errors) && module_initialized && EG(active_symbol_table) && 
+       if (PG(track_errors) && module_initialized && 
                        (!EG(user_error_handler) || !(EG(user_error_handler_error_reporting) & type))) {
-               zval *tmp;
-               ALLOC_INIT_ZVAL(tmp);
-               ZVAL_STRINGL(tmp, buffer, buffer_len, 1);
-               zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) &tmp, sizeof(zval *), NULL);
+               if (!EG(active_symbol_table)) {
+                       zend_rebuild_symbol_table(TSRMLS_C);
+               }
+               if (EG(active_symbol_table)) {
+                       zval *tmp;
+                       ALLOC_INIT_ZVAL(tmp);
+                       ZVAL_STRINGL(tmp, buffer, buffer_len, 1);
+                       zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) &tmp, sizeof(zval *), NULL);
+               }
        }
        efree(buffer);
 
@@ -1033,11 +1038,16 @@ static void php_error_cb(int type, const char *error_filename, const uint error_
                return;
        }
 
-       if (PG(track_errors) && module_initialized && EG(active_symbol_table)) {
-               zval *tmp;
-               ALLOC_INIT_ZVAL(tmp);
-               ZVAL_STRINGL(tmp, buffer, buffer_len, 1);
-               zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) & tmp, sizeof(zval *), NULL);
+       if (PG(track_errors) && module_initialized) {
+               if (!EG(active_symbol_table)) {
+                       zend_rebuild_symbol_table(TSRMLS_C);
+               }
+               if (EG(active_symbol_table)) {
+                       zval *tmp;
+                       ALLOC_INIT_ZVAL(tmp);
+                       ZVAL_STRINGL(tmp, buffer, buffer_len, 1);
+                       zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) & tmp, sizeof(zval *), NULL);
+               }
        }
 
        efree(buffer);