]> granicus.if.org Git - php/commitdiff
Fixed bug #38325 (spl_autoload_register() gaves wrong line for "class
authorIlia Alshanetsky <iliaa@php.net>
Mon, 8 Jan 2007 04:27:29 +0000 (04:27 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Mon, 8 Jan 2007 04:27:29 +0000 (04:27 +0000)
not found").

NEWS
ext/spl/php_spl.c
ext/spl/tests/bug38325.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 15ff376ebacf3a5168061baf9412c0bc3ede9acc..04397ae7bbe1dc8fe01d68ec6e81f5f47f75b9cb 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,8 @@ PHP                                                                        NEWS
 - Fixed bug #39504 (xmlwriter_write_dtd_entity() creates Attlist tag,
   not entity). (Hannes)
 - Fixed bug #39394 (Missing check for older variants of openssl). (Ilia)
+- Fixed bug #38325 (spl_autoload_register() gaves wrong line for "class
+  not found"). (Ilia)
 
 04 Jan 2007, PHP 5.2.1RC2
 - Small optimization of the date() function (Matt,Ilia)
index 7029139c67a3fb2a260ea5fbda91fe404fa63512..b8e1cfbe199a87f9145d49306e27c6cd1a6f6ebc 100755 (executable)
@@ -297,7 +297,15 @@ PHP_FUNCTION(spl_autoload)
        EG(function_state_ptr) = original_function_state_ptr;
 
        if (!found && !SPL_G(autoload_running)) {
-               zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Class %s could not be loaded", class_name);
+               /* For internal errors, we generate E_ERROR, for direct calls an exception is thrown.
+                * The "scope" is determined by an opcode, if it is ZEND_FETCH_CLASS we know function was called indirectly by
+                * the Zend engine.
+                */
+               if (active_opline->opcode != ZEND_FETCH_CLASS) {
+                       zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Class %s could not be loaded", class_name);
+               } else {
+                       php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %s could not be loaded", class_name);
+               }
        }
 } /* }}} */
 
diff --git a/ext/spl/tests/bug38325.phpt b/ext/spl/tests/bug38325.phpt
new file mode 100644 (file)
index 0000000..126e1f3
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+Bug #38325 (spl_autoload_register() gaves wrong line for "class not found")
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--FILE--
+<?php
+spl_autoload_register();
+new Foo();
+?>
+--EXPECTF--
+Fatal error: spl_autoload(): Class Foo could not be loaded in %s on line 3