]> granicus.if.org Git - php/commitdiff
MFH Fix bug #48493 - spl_autoload_register can leave the HT in an inconsistent way.
authorScott MacVicar <scottmac@php.net>
Tue, 9 Jun 2009 01:58:07 +0000 (01:58 +0000)
committerScott MacVicar <scottmac@php.net>
Tue, 9 Jun 2009 01:58:07 +0000 (01:58 +0000)
Need to point the second elements previous item to head so we can traverse upwards.

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

index dda04cbd0171261c3e68c0d94b2d829ab8591e4b..2e34f46e640040c3d3307e8de192ba0ba4f2129f 100755 (executable)
@@ -415,6 +415,7 @@ PHP_FUNCTION(spl_autoload_call)
        (ht)->pListTail->pListNext = (ht)->pListHead;                   \
        (ht)->pListHead = (ht)->pListTail;                                              \
        (ht)->pListTail = (ht)->pListHead->pListLast;                   \
+       (ht)->pListHead->pListNext->pListLast = (ht)->pListHead;\
        (ht)->pListTail->pListNext = NULL;                                              \
        (ht)->pListHead->pListLast = NULL;
 
diff --git a/ext/spl/tests/bug48493.phpt b/ext/spl/tests/bug48493.phpt
new file mode 100644 (file)
index 0000000..d0be7f8
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+SPL: Bug #48493 spl_autoload_unregister() can't handle prepended functions
+--FILE--
+<?php
+function autoload1() {}
+
+function autoload2() {}
+
+spl_autoload_register('autoload2');
+spl_autoload_register('autoload1', true, true);
+var_dump(spl_autoload_functions());
+
+spl_autoload_unregister('autoload2');
+var_dump(spl_autoload_functions());
+?>
+--EXPECT--
+array(2) {
+  [0]=>
+  string(9) "autoload1"
+  [1]=>
+  string(9) "autoload2"
+}
+array(1) {
+  [0]=>
+  string(9) "autoload1"
+}