summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2016-03-18 20:26:24 +0100
committerNikita Popov <nikic@php.net>2016-03-18 20:28:58 +0100
commit8023204d219d353b83f19edb0133483d67aedcfb (patch)
treeca448deda1e233f90e90ed00206dc5dcf2432942
parenta2522efa9ff409c2cbce7111735e0982e9cad1e6 (diff)
downloadphp-git-8023204d219d353b83f19edb0133483d67aedcfb.tar.gz
Fixed bug #52339
Autoloader 101: Don't throw if you fail. PHP will throw for you.
-rw-r--r--NEWS1
-rw-r--r--ext/spl/php_spl.c22
-rw-r--r--ext/spl/tests/bug38325.phpt5
-rw-r--r--ext/spl/tests/bug52339.phpt11
-rw-r--r--ext/spl/tests/spl_autoload_001.phpt71
5 files changed, 39 insertions, 71 deletions
diff --git a/NEWS b/NEWS
index 1005c3e7d3..0a93b9824d 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,7 @@ PHP NEWS
- SPL:
. Fixed bug #71838 (Deserializing serialized SPLObjectStorage-Object can't
access properties in PHP). (Nikita)
+ . Fixed bug #52339 (SPL autoloader breaks class_exists()). (Nikita)
- Standard:
. Fixed bug #71837 (Wrong arrays behaviour). (Laruence)
diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c
index 9c7611d117..87fb2ae37b 100644
--- a/ext/spl/php_spl.c
+++ b/ext/spl/php_spl.c
@@ -307,7 +307,7 @@ static int spl_autoload(zend_string *class_name, zend_string *lc_name, const cha
Default implementation for __autoload() */
PHP_FUNCTION(spl_autoload)
{
- int found = 0, pos_len, pos1_len;
+ int pos_len, pos1_len;
char *pos, *pos1;
zend_string *class_name, *lc_name, *file_exts = SPL_G(autoload_extensions);
@@ -333,32 +333,12 @@ PHP_FUNCTION(spl_autoload)
pos1_len = pos_len;
}
if (spl_autoload(class_name, lc_name, pos, pos1_len)) {
- found = 1;
break; /* loaded */
}
pos = pos1 ? pos1 + 1 : NULL;
pos_len = pos1? pos_len - pos1_len - 1 : 0;
}
zend_string_free(lc_name);
-
- if (!found && !SPL_G(autoload_running)) {
- /* 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.
- */
- zend_execute_data *ex = EX(prev_execute_data);
-
- while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
- ex = ex->prev_execute_data;
- }
- if (ex &&
- ex->opline->opcode != ZEND_FETCH_CLASS &&
- ex->opline->opcode != ZEND_NEW) {
- zend_throw_exception_ex(spl_ce_LogicException, 0, "Class %s could not be loaded", ZSTR_VAL(class_name));
- } else {
- php_error_docref(NULL, E_ERROR, "Class %s could not be loaded", ZSTR_VAL(class_name));
- }
- }
} /* }}} */
/* {{{ proto string spl_autoload_extensions([string file_extensions])
diff --git a/ext/spl/tests/bug38325.phpt b/ext/spl/tests/bug38325.phpt
index ddb2829da4..1911fc8eaf 100644
--- a/ext/spl/tests/bug38325.phpt
+++ b/ext/spl/tests/bug38325.phpt
@@ -6,4 +6,7 @@ spl_autoload_register();
new ThisClassDoesNotExistEverFoo();
?>
--EXPECTF--
-Fatal error: spl_autoload(): Class ThisClassDoesNotExistEverFoo could not be loaded in %s on line 3
+Fatal error: Uncaught Error: Class 'ThisClassDoesNotExistEverFoo' not found in %s:%d
+Stack trace:
+#0 {main}
+ thrown in %s on line 3
diff --git a/ext/spl/tests/bug52339.phpt b/ext/spl/tests/bug52339.phpt
new file mode 100644
index 0000000000..2e24898fa9
--- /dev/null
+++ b/ext/spl/tests/bug52339.phpt
@@ -0,0 +1,11 @@
+--TEST--
+Bug #52339: SPL autoloader breaks class_exists()
+--FILE--
+<?php
+var_dump(class_exists('asdfasdf'));
+spl_autoload_register();
+var_dump(class_exists('asdfasdf'));
+?>
+--EXPECT--
+bool(false)
+bool(false)
diff --git a/ext/spl/tests/spl_autoload_001.phpt b/ext/spl/tests/spl_autoload_001.phpt
index ff9d1e97d9..fc5f6ed4f7 100644
--- a/ext/spl/tests/spl_autoload_001.phpt
+++ b/ext/spl/tests/spl_autoload_001.phpt
@@ -9,38 +9,25 @@ echo "===EMPTY===\n";
var_dump(spl_autoload_extensions());
-try
-{
- spl_autoload("TestClass");
-}
-catch(Exception $e)
-{
- echo 'Exception: ' . $e->getMessage() . "\n";
+spl_autoload("TestClass");
+if (!class_exists("TestClass")) {
+ echo "Class TestClass could not be loaded\n";
}
$test_exts = array(NULL, "1", ".inc,,.php.inc", "");
-foreach($test_exts as $exts)
-{
+foreach($test_exts as $exts) {
echo "===($exts)===\n";
- try
- {
- spl_autoload("TestClass", $exts);
- }
- catch(Exception $e)
- {
- echo 'Exception: ' . $e->getMessage() . "\n";
- }
+ spl_autoload("TestClass", $exts);
+ if (!class_exists("TestClass")) {
+ echo "Class TestClass could not be loaded\n";
+ }
}
-try
-{
- spl_autoload_extensions(".inc,.php.inc");
- spl_autoload("TestClass");
-}
-catch(Exception $e)
-{
- echo 'Exception: ' . $e->getMessage() . "\n";
+spl_autoload_extensions(".inc,.php.inc");
+spl_autoload("TestClass");
+if (!class_exists("TestClass")) {
+ echo "Class TestClass could not be loaded\n";
}
function TestFunc1($classname)
@@ -57,15 +44,8 @@ echo "===SPL_AUTOLOAD()===\n";
spl_autoload_register();
-try
-{
- var_dump(spl_autoload_extensions(".inc"));
- var_dump(class_exists("TestClass", true));
-}
-catch(Exception $e)
-{
- echo 'Exception: ' . $e->getMessage() . "\n";
-}
+var_dump(spl_autoload_extensions(".inc"));
+var_dump(class_exists("TestClass", true));
echo "===REGISTER===\n";
@@ -75,14 +55,7 @@ spl_autoload_register("TestFunc2");
spl_autoload_register("TestFunc2"); /* 2nd call ignored */
spl_autoload_extensions(".inc,.class.inc"); /* we do not have spl_autoload_registered yet */
-try
-{
- var_dump(class_exists("TestClass", true));
-}
-catch(Exception $e)
-{
- echo 'Exception: ' . $e->getMessage() . "\n";
-}
+var_dump(class_exists("TestClass", true));
echo "===LOAD===\n";
@@ -107,21 +80,21 @@ catch(Exception $e)
===EMPTY===
string(9) ".inc,.php"
%stestclass.inc
-Exception: Class TestClass could not be loaded
+Class TestClass could not be loaded
===()===
-Exception: Class TestClass could not be loaded
+Class TestClass could not be loaded
===(1)===
-Exception: Class TestClass could not be loaded
+Class TestClass could not be loaded
===(.inc,,.php.inc)===
%stestclass
%stestclass.php.inc
-Exception: Class TestClass could not be loaded
+Class TestClass could not be loaded
===()===
-Exception: Class TestClass could not be loaded
-Exception: Class TestClass could not be loaded
+Class TestClass could not be loaded
+Class TestClass could not be loaded
===SPL_AUTOLOAD()===
string(4) ".inc"
-Exception: Class TestClass could not be loaded
+bool(false)
===REGISTER===
TestFunc1(TestClass)
TestFunc2(TestClass)