]> 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:46 +0000 (09:20 +0000)
committerDmitry Stogov <dmitry@php.net>
Mon, 9 Feb 2009 09:20:46 +0000 (09:20 +0000)
Zend/tests/bug47320.phpt [new file with mode: 0644]
Zend/zend_execute_API.c
main/main.c

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 53873b16e8e25c05a50eaf7fe361a0650670988d..0851aa1c20e7333b444807ee7bf0fb487772325a 100644 (file)
@@ -1785,15 +1785,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 4b3965f570cab2495a5b78727dd26a4ed4c17da8..5dd7dad75edb3d49868f2609f7427b69fd1b904f 100644 (file)
@@ -853,12 +853,17 @@ PHPAPI void php_verror(const char *docref, const char *params, int type, const c
        php_error(type, "%s", message);
        efree(message);
 
-       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_RT_STRINGL(tmp, buffer, buffer_len, 1);
-               zend_ascii_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_RT_STRINGL(tmp, buffer, buffer_len, 1);
+                       zend_ascii_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) &tmp, sizeof(zval *), NULL);
+               }
        }
        efree(buffer);
 }
@@ -1125,12 +1130,17 @@ static void php_error_cb(int type, const char *error_filename, const uint error_
                efree(buffer);
                return;
        }
-       if (PG(track_errors) && module_initialized && EG(active_symbol_table)) {
-               zval *tmp;
+       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_RT_STRINGL(tmp, buffer, buffer_len, 1);
-               zend_ascii_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) & tmp, sizeof(zval *), NULL);
+                       ALLOC_INIT_ZVAL(tmp);
+                       ZVAL_RT_STRINGL(tmp, buffer, buffer_len, 1);
+                       zend_ascii_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) & tmp, sizeof(zval *), NULL);
+               }
        }
        efree(buffer);
 }