]> granicus.if.org Git - php/commitdiff
- Fixed Bug #39313 spl_autoload triggers Fatal error
authorMarcus Boerger <helly@php.net>
Tue, 31 Oct 2006 23:18:00 +0000 (23:18 +0000)
committerMarcus Boerger <helly@php.net>
Tue, 31 Oct 2006 23:18:00 +0000 (23:18 +0000)
ext/spl/php_spl.c
ext/spl/php_spl.h
ext/spl/tests/spl_autoload_009.phpt [new file with mode: 0755]

index 18046a436bf13f64d426ae4a4272527046ccaa16..b0d10eafb34487df2108d5888d292cad1585951d 100755 (executable)
@@ -57,6 +57,7 @@ static PHP_GINIT_FUNCTION(spl)
 {
        spl_globals->autoload_extensions = NULL;
        spl_globals->autoload_functions  = NULL;
+       spl_globals->autoload_running    = 0;
 }
 /* }}} */
 
@@ -303,7 +304,7 @@ PHP_FUNCTION(spl_autoload)
        EG(active_op_array) = original_active_op_array;
        EG(function_state_ptr) = original_function_state_ptr;
 
-       if (!found) {
+       if (!found && !SPL_G(autoload_running)) {
                zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Class %s could not be loaded", class_name);
        }
 } /* }}} */
@@ -360,6 +361,8 @@ PHP_FUNCTION(spl_autoload_call)
        }
 
        if (SPL_G(autoload_functions)) {
+               int l_autoload_running = SPL_G(autoload_running);
+               SPL_G(autoload_running) = 1;
                class_name_type = Z_TYPE_P(class_name);
                class_name_len = Z_UNILEN_P(class_name);
                lc_name = zend_u_str_tolower_dup(class_name_type, Z_UNIVAL_P(class_name), class_name_len);
@@ -378,6 +381,7 @@ PHP_FUNCTION(spl_autoload_call)
                        zend_hash_move_forward_ex(SPL_G(autoload_functions), &function_pos);
                }
                efree(lc_name.v);
+               SPL_G(autoload_running) = l_autoload_running;
        } else {
                /* do not use or overwrite &EG(autoload_func) here */
                zend_call_method_with_1_params(NULL, NULL, NULL, "spl_autoload", NULL, class_name);
index 4e8c9b3f7d3b2e4b2f76048555718845a903625f..fd8e5cb8b9cd9f0fdab8682e3f3131a2ddb0ee9e 100755 (executable)
@@ -58,6 +58,7 @@ PHP_MINFO_FUNCTION(spl);
 ZEND_BEGIN_MODULE_GLOBALS(spl)
        char *       autoload_extensions;
        HashTable *  autoload_functions;
+       int          autoload_running;
 ZEND_END_MODULE_GLOBALS(spl)
 
 #ifdef ZTS
diff --git a/ext/spl/tests/spl_autoload_009.phpt b/ext/spl/tests/spl_autoload_009.phpt
new file mode 100755 (executable)
index 0000000..c282bf4
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+SPL: spl_autoload() and friends
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--INI--
+include_path=.
+--FILE--
+<?php
+
+function my_autoload($name)
+{
+       require $name . '.class.inc';
+       var_dump(class_exists($name));
+}
+
+spl_autoload_register("spl_autoload");
+spl_autoload_register("my_autoload");
+
+$obj = new testclass;
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECTF--
+%stestclass.inc
+%stestclass.class.inc
+bool(true)
+===DONE===