diff --git a/Zend/tests/autoload/class/autoload_call_basic.phpt b/Zend/tests/autoload/class/autoload_call_basic.phpt new file mode 100644 index 000000000000..eae6361fe89c --- /dev/null +++ b/Zend/tests/autoload/class/autoload_call_basic.phpt @@ -0,0 +1,17 @@ +--TEST-- +Basic autoload_call_class() function +--CREDITS-- +Jean-Marc Fontaine +# Alter Way Contribution Day 2011 +--FILE-- + +--EXPECT-- +bool(true) diff --git a/Zend/tests/autoload/class/autoload_call_invalid_name.phpt b/Zend/tests/autoload/class/autoload_call_invalid_name.phpt new file mode 100644 index 000000000000..95ffae3569b2 --- /dev/null +++ b/Zend/tests/autoload/class/autoload_call_invalid_name.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test autoload_call_class() with invalid symbol name +--FILE-- +getMessage(); +} +try { + autoload_call_class('"'); +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(); +} +try { + autoload_call_class(''); +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(); +} +try { + autoload_call_class("al\no"); +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(); +} +?> +--EXPECT-- +string(6) "12ayhs" +string(1) """ +string(0) "" +string(4) "al +o" diff --git a/Zend/tests/autoload/class/autoload_called_scope.phpt b/Zend/tests/autoload/class/autoload_called_scope.phpt new file mode 100644 index 000000000000..d19fc3d9c91d --- /dev/null +++ b/Zend/tests/autoload/class/autoload_called_scope.phpt @@ -0,0 +1,33 @@ +--TEST-- +Autoloader should not do anything magic with called scope +--FILE-- + +--EXPECT-- +self=Test, static=Test +self=Test, static=Test2 diff --git a/Zend/tests/autoload/class/autoload_invalid_name_variable.phpt b/Zend/tests/autoload/class/autoload_invalid_name_variable.phpt new file mode 100644 index 000000000000..124db5d268a4 --- /dev/null +++ b/Zend/tests/autoload/class/autoload_invalid_name_variable.phpt @@ -0,0 +1,41 @@ +--TEST-- +Dynamic autoload with invalid symbol name in variable +--FILE-- +getMessage(), \PHP_EOL; +} +$name = '"'; +try { + new $name; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), \PHP_EOL; +} +$name = ''; +try { + new $name; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), \PHP_EOL; +} +$name = "al\no"; +try { + new $name; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), \PHP_EOL; +} +?> +--EXPECT-- +string(6) "12ayhs" +Error: Class "12ayhs" not found +Error: Class """ not found +Error: Class "" not found +Error: Class "al +o" not found diff --git a/Zend/tests/autoload/class/autoloader_with_closures_and_invocables.phpt b/Zend/tests/autoload/class/autoloader_with_closures_and_invocables.phpt new file mode 100644 index 000000000000..08a9fe8d3b88 --- /dev/null +++ b/Zend/tests/autoload/class/autoloader_with_closures_and_invocables.phpt @@ -0,0 +1,68 @@ +--TEST-- +Autoloading with closures and invocables +--FILE-- +dir}') called with $class\n"); + } +} + +class WorkingAutoloader { + public function __invoke($class) { + echo ("WorkingAutoloader() called with $class\n"); + eval("class $class { }"); + } +} + +$al1 = new Autoloader('d1'); +$al2 = new WorkingAutoloader('d2'); + +autoload_register_class($closure); +autoload_register_class($al1); +autoload_register_class($al2); + +var_dump(autoload_list_class()); + +$x = new TestX; + +autoload_unregister_class($closure); +autoload_unregister_class($al1); + +$y = new TestY; + +?> +--EXPECTF-- +array(3) { + [0]=> + object(Closure)#1 (4) { + ["name"]=> + string(%d) "{closure:%s:%d}" + ["file"]=> + string(%d) "%s" + ["line"]=> + int(2) + ["parameter"]=> + array(1) { + ["$name"]=> + string(10) "" + } + } + [1]=> + object(Autoloader)#2 (1) { + ["dir":"Autoloader":private]=> + string(2) "d1" + } + [2]=> + object(WorkingAutoloader)#3 (0) { + } +} +autoload(TestX) +Autoloader('d1') called with TestX +WorkingAutoloader() called with TestX +WorkingAutoloader() called with TestY diff --git a/Zend/tests/autoload/bug42798.phpt b/Zend/tests/autoload/class/bug42798.phpt similarity index 55% rename from Zend/tests/autoload/bug42798.phpt rename to Zend/tests/autoload/class/bug42798.phpt index 5f19fe308025..23a38b7cbc73 100644 --- a/Zend/tests/autoload/bug42798.phpt +++ b/Zend/tests/autoload/class/bug42798.phpt @@ -1,8 +1,8 @@ --TEST-- -Bug #42798 (_autoload() not triggered for classes used in method signature) +Bug #42798 (Autoloading not triggered for classes used in method signature) --FILE-- --EXPECTF-- diff --git a/Zend/tests/autoload/class/bug71204.phpt b/Zend/tests/autoload/class/bug71204.phpt new file mode 100644 index 000000000000..bb75036ed9c0 --- /dev/null +++ b/Zend/tests/autoload/class/bug71204.phpt @@ -0,0 +1,19 @@ +--TEST-- +Bug #71204 (segfault if clean autoloaders while autoloading) +--FILE-- + +--EXPECTF-- +Fatal error: Uncaught Error: Class "A" not found in %s:%d +Stack trace: +#0 {main} + thrown in %sbug71204.php on line %d diff --git a/ext/spl/tests/autoloading/bug73896.phpt b/Zend/tests/autoload/class/bug73896.phpt similarity index 70% rename from ext/spl/tests/autoloading/bug73896.phpt rename to Zend/tests/autoload/class/bug73896.phpt index 657f30c50dbe..3e32bac243e4 100644 --- a/ext/spl/tests/autoloading/bug73896.phpt +++ b/Zend/tests/autoload/class/bug73896.phpt @@ -1,16 +1,16 @@ --TEST-- -Bug #73896 (spl_autoload() crashes when calls magic _call()) +Bug #73896 (autoload_register_class() crashes when calls magic __call()) --FILE-- var."\n"; + } + public function __destruct() { + echo "__destruct__\n"; + } +} + +$a = new A; +$a->var = 2; + +autoload_register_class(array($a, 'autoload')); +unset($a); + +var_dump(class_exists("C", true)); +?> +===DONE=== +--EXPECT-- +var:2 +bool(false) +===DONE=== +__destruct__ diff --git a/Zend/tests/autoload/class/emit-parse-error-in-autoloader.phpt b/Zend/tests/autoload/class/emit-parse-error-in-autoloader.phpt new file mode 100644 index 000000000000..a5c70c8faf1a --- /dev/null +++ b/Zend/tests/autoload/class/emit-parse-error-in-autoloader.phpt @@ -0,0 +1,17 @@ +--TEST-- +Parse errors should be thrown if occuring from an autoloader +--FILE-- + +--EXPECTF-- +Parse error: syntax error, unexpected identifier "ha" in %s on line %d diff --git a/Zend/tests/autoload/class/exceptions_during_autoloading001.phpt b/Zend/tests/autoload/class/exceptions_during_autoloading001.phpt new file mode 100644 index 000000000000..29ab61f8858a --- /dev/null +++ b/Zend/tests/autoload/class/exceptions_during_autoloading001.phpt @@ -0,0 +1,33 @@ +--TEST-- +Exception thrown from within autoloading function +--FILE-- +getMessage() . "\n"; +} + +?> +--EXPECT-- +TestFunc1(TestClass) +TestFunc2(TestClass) +Exception: Class TestClass missing diff --git a/Zend/tests/autoload/class/exceptions_during_autoloading002.phpt b/Zend/tests/autoload/class/exceptions_during_autoloading002.phpt new file mode 100644 index 000000000000..e1baf602e96f --- /dev/null +++ b/Zend/tests/autoload/class/exceptions_during_autoloading002.phpt @@ -0,0 +1,127 @@ +--TEST-- +Exceptions during autoloading +--FILE-- + $func) +{ + echo "====$idx====\n"; + + var_dump($func); + try { + autoload_register_class($func); + } catch (TypeError $e) { + echo get_class($e) . ': ' . $e->getMessage() . \PHP_EOL; + var_dump(count(autoload_list_class())); + continue; + } + + if (count(autoload_list_class())) { + echo "registered\n"; + + try { + var_dump(class_exists("NoExistingTestClass", true)); + } catch (Exception $e) { + echo get_class($e) . ': ' . $e->getMessage() . \PHP_EOL; + } + } + + autoload_unregister_class($func); + var_dump(count(autoload_list_class())); +} + +?> +--EXPECTF-- +====0==== +string(10) "MyAutoLoad" +registered +MyAutoLoad(NoExistingTestClass) +Exception: Bla +int(0) +====1==== +string(22) "MyAutoLoader::autoLoad" +registered +MyAutoLoader::autoLoad(NoExistingTestClass) +Exception: Bla +int(0) +====2==== +string(22) "MyAutoLoader::dynaLoad" +TypeError: autoload_register_class(): Argument #1 ($callback) must be a valid callback, non-static method MyAutoLoader::dynaLoad() cannot be called statically +int(0) +====3==== +array(2) { + [0]=> + string(12) "MyAutoLoader" + [1]=> + string(8) "autoLoad" +} +registered +MyAutoLoader::autoLoad(NoExistingTestClass) +Exception: Bla +int(0) +====4==== +array(2) { + [0]=> + string(12) "MyAutoLoader" + [1]=> + string(8) "dynaLoad" +} +TypeError: autoload_register_class(): Argument #1 ($callback) must be a valid callback, non-static method MyAutoLoader::dynaLoad() cannot be called statically +int(0) +====5==== +array(2) { + [0]=> + object(MyAutoLoader)#%d (0) { + } + [1]=> + string(8) "autoLoad" +} +registered +MyAutoLoader::autoLoad(NoExistingTestClass) +Exception: Bla +int(0) +====6==== +array(2) { + [0]=> + object(MyAutoLoader)#%d (0) { + } + [1]=> + string(8) "dynaLoad" +} +registered +MyAutoLoader::dynaLoad(NoExistingTestClass) +Exception: Bla +int(0) diff --git a/Zend/tests/autoload/class/exceptions_during_autoloading003.phpt b/Zend/tests/autoload/class/exceptions_during_autoloading003.phpt new file mode 100644 index 000000000000..45ef5599f7cc --- /dev/null +++ b/Zend/tests/autoload/class/exceptions_during_autoloading003.phpt @@ -0,0 +1,50 @@ +--TEST-- +Capturing multiple Exceptions during autoloading +--FILE-- +getMessage()."\n"; + } while($e = $e->getPrevious()); +} + +try { + new ThisClassDoesNotExist; +} catch(Exception $e) { + do { + echo $e->getMessage()."\n"; + } while($e = $e->getPrevious()); +} + +class_exists('ThisClassDoesNotExist'); +?> +===DONE=== +--EXPECTF-- +autoload_first +first +autoload_first +first +autoload_first + +Fatal error: Uncaught Exception: first in %s:%d +Stack trace: +#0 [internal function]: autoload_first('ThisClassDoesNo...') +#1 %s(%d): class_exists('ThisClassDoesNo...') +#2 {main} + thrown in %s on line %d diff --git a/Zend/tests/autoload/class/innacessible_methods.phpt b/Zend/tests/autoload/class/innacessible_methods.phpt new file mode 100644 index 000000000000..b0bad49ffe61 --- /dev/null +++ b/Zend/tests/autoload/class/innacessible_methods.phpt @@ -0,0 +1,132 @@ +--TEST-- +Autoloading inaccessible methods +--INI-- +include_path=. +--FILE-- + $func) +{ + if ($idx) echo "\n"; + try { + var_dump($func); + autoload_register_class($func); + echo "ok\n"; + } catch(\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; + } +} + +?> +--EXPECTF-- +string(22) "MyAutoLoader::notExist" +autoload_register_class(): Argument #1 ($callback) must be a valid callback, class MyAutoLoader does not have a method "notExist" + +string(22) "MyAutoLoader::noAccess" +autoload_register_class(): Argument #1 ($callback) must be a valid callback, cannot access protected method MyAutoLoader::noAccess() + +string(22) "MyAutoLoader::autoLoad" +ok + +string(22) "MyAutoLoader::dynaLoad" +autoload_register_class(): Argument #1 ($callback) must be a valid callback, non-static method MyAutoLoader::dynaLoad() cannot be called statically + +array(2) { + [0]=> + string(12) "MyAutoLoader" + [1]=> + string(8) "notExist" +} +autoload_register_class(): Argument #1 ($callback) must be a valid callback, class MyAutoLoader does not have a method "notExist" + +array(2) { + [0]=> + string(12) "MyAutoLoader" + [1]=> + string(8) "noAccess" +} +autoload_register_class(): Argument #1 ($callback) must be a valid callback, cannot access protected method MyAutoLoader::noAccess() + +array(2) { + [0]=> + string(12) "MyAutoLoader" + [1]=> + string(8) "autoLoad" +} +ok + +array(2) { + [0]=> + string(12) "MyAutoLoader" + [1]=> + string(8) "dynaLoad" +} +autoload_register_class(): Argument #1 ($callback) must be a valid callback, non-static method MyAutoLoader::dynaLoad() cannot be called statically + +array(2) { + [0]=> + object(MyAutoLoader)#%d (0) { + } + [1]=> + string(8) "notExist" +} +autoload_register_class(): Argument #1 ($callback) must be a valid callback, class MyAutoLoader does not have a method "notExist" + +array(2) { + [0]=> + object(MyAutoLoader)#%d (0) { + } + [1]=> + string(8) "noAccess" +} +autoload_register_class(): Argument #1 ($callback) must be a valid callback, cannot access protected method MyAutoLoader::noAccess() + +array(2) { + [0]=> + object(MyAutoLoader)#%d (0) { + } + [1]=> + string(8) "autoLoad" +} +ok + +array(2) { + [0]=> + object(MyAutoLoader)#%d (0) { + } + [1]=> + string(8) "dynaLoad" +} +ok diff --git a/Zend/tests/autoload/class/methods.phpt b/Zend/tests/autoload/class/methods.phpt new file mode 100644 index 000000000000..f2f37f70ed23 --- /dev/null +++ b/Zend/tests/autoload/class/methods.phpt @@ -0,0 +1,43 @@ +--TEST-- +Autoloader is a method +--FILE-- +getMessage() . \PHP_EOL; +} + +// and + +$myAutoLoader = new MyAutoLoader(); + +autoload_register_class(array($myAutoLoader, 'autoLoad')); +autoload_register_class(array($myAutoLoader, 'autoThrow')); + +try { + var_dump(class_exists("TestClass", true)); +} catch(Exception $e) { + echo 'Exception: ' . $e->getMessage() . "\n"; +} + +?> +--EXPECT-- +autoload_register_class(): Argument #1 ($callback) must be a valid callback, non-static method MyAutoLoader::autoLoad() cannot be called statically +MyAutoLoader::autoLoad(TestClass) +MyAutoLoader::autoThrow(TestClass) +Exception: Unavailable diff --git a/Zend/tests/autoload/class/prepending.phpt b/Zend/tests/autoload/class/prepending.phpt new file mode 100644 index 000000000000..6b048732c683 --- /dev/null +++ b/Zend/tests/autoload/class/prepending.phpt @@ -0,0 +1,34 @@ +--TEST-- +Prepending autoloaders +--FILE-- + $name\n"; +} +function autoloadB($name) { + echo "B -> $name\n"; +} +function autoloadC($name) { + echo "C -> $name\n"; + class C{} +} + +autoload_register_class('autoloadA'); +autoload_register_class('autoloadB', true); +autoload_register_class('autoloadC'); +var_dump(autoload_list_class()); + +new C; +?> +--EXPECT-- +array(3) { + [0]=> + string(9) "autoloadB" + [1]=> + string(9) "autoloadA" + [2]=> + string(9) "autoloadC" +} +B -> C +A -> C +C -> C diff --git a/Zend/tests/autoload/class/register_class.phpt b/Zend/tests/autoload/class/register_class.phpt new file mode 100644 index 000000000000..d44fcbcda3b7 --- /dev/null +++ b/Zend/tests/autoload/class/register_class.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test autoload_register_class(): basic function behavior 001 +--FILE-- +getMessage(), \PHP_EOL; +} +*/ +echo "===EMPTY===\n"; + +function TestFunc1($classname) { + echo __METHOD__ . "($classname)\n"; +} + +function TestFunc2($classname) { + echo __METHOD__ . "($classname)\n"; +} + +echo "===REGISTER===\n"; + +autoload_register_class("TestFunc1"); +autoload_register_class("TestFunc2"); +autoload_register_class("TestFunc2"); // 2nd call ignored + +var_dump(class_exists("TestClass", true)); + +echo "===LOAD===\n"; + +autoload_register_class("spl_autoload"); +var_dump(class_exists("TestClass", true)); + +echo "===NOFUNCTION===\n"; + +try { + autoload_register_class("unavailable_autoload_function"); +} catch(\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} + +?> +--EXPECT-- +===EMPTY=== +===REGISTER=== +TestFunc1(TestClass) +TestFunc2(TestClass) +bool(false) +===LOAD=== +TestFunc1(TestClass) +TestFunc2(TestClass) +bool(false) +===NOFUNCTION=== +autoload_register_class(): Argument #1 ($callback) must be a valid callback, function "unavailable_autoload_function" not found or invalid function name diff --git a/Zend/tests/autoload/class/same_class_different_instances.phpt b/Zend/tests/autoload/class/same_class_different_instances.phpt new file mode 100644 index 000000000000..a995b26532f3 --- /dev/null +++ b/Zend/tests/autoload/class/same_class_different_instances.phpt @@ -0,0 +1,47 @@ +--TEST-- +Registering two different instance of a class as an autoloader should work +--FILE-- +directory_to_use, "\n"; + } +} + +$autoloader1 = new MyAutoloader('dir1'); +autoload_register_class(array($autoloader1, 'autoload')); + +$autoloader2 = new MyAutoloader('dir2'); +autoload_register_class(array($autoloader2, 'autoload')); + +var_dump(autoload_list_class()); +var_dump(class_exists('NonExisting')); + +?> +--EXPECT-- +array(2) { + [0]=> + array(2) { + [0]=> + object(MyAutoloader)#1 (1) { + ["directory_to_use":"MyAutoloader":private]=> + string(4) "dir1" + } + [1]=> + string(8) "autoload" + } + [1]=> + array(2) { + [0]=> + object(MyAutoloader)#2 (1) { + ["directory_to_use":"MyAutoloader":private]=> + string(4) "dir2" + } + [1]=> + string(8) "autoload" + } +} +dir1 +dir2 +bool(false) diff --git a/Zend/tests/autoload/class/static_methods.phpt b/Zend/tests/autoload/class/static_methods.phpt new file mode 100644 index 000000000000..c6903ad337b6 --- /dev/null +++ b/Zend/tests/autoload/class/static_methods.phpt @@ -0,0 +1,31 @@ +--TEST-- +Autoloader is a static method +--FILE-- + +--EXPECT-- +array(1) { + [0]=> + array(2) { + [0]=> + string(12) "MyAutoLoader" + [1]=> + string(8) "autoLoad" + } +} +MyAutoLoader::autoLoad(TestClass) +bool(false) diff --git a/Zend/tests/autoload/class/throw_with_autoload_call_as_autoloader.phpt b/Zend/tests/autoload/class/throw_with_autoload_call_as_autoloader.phpt new file mode 100644 index 000000000000..484b5366eba7 --- /dev/null +++ b/Zend/tests/autoload/class/throw_with_autoload_call_as_autoloader.phpt @@ -0,0 +1,14 @@ +--TEST-- +Throw when using autoload_register_class() as the autoloading function +--FILE-- +getMessage() . \PHP_EOL; +} + +?> +--EXPECT-- +autoload_register_class(): Argument #1 ($callback) must not be the autoload_call_class() function diff --git a/Zend/tests/autoload/class/trampoline_autoloader.phpt b/Zend/tests/autoload/class/trampoline_autoloader.phpt new file mode 100644 index 000000000000..506c5333f048 --- /dev/null +++ b/Zend/tests/autoload/class/trampoline_autoloader.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test autoload_unregister_class(): behavior with a trampoline +--FILE-- + +--EXPECT-- +array(2) { + [0]=> + array(2) { + [0]=> + object(TrampolineTest)#1 (0) { + } + [1]=> + string(11) "trampoline1" + } + [1]=> + array(2) { + [0]=> + object(TrampolineTest)#1 (0) { + } + [1]=> + string(11) "trampoline2" + } +} +Trampoline for trampoline1 +Trampoline for trampoline2 +bool(false) +Unregister trampoline: +bool(true) +bool(false) +bool(true) +bool(false) diff --git a/Zend/tests/autoload/class/trampoline_unregister_autoloader_from_list.phpt b/Zend/tests/autoload/class/trampoline_unregister_autoloader_from_list.phpt new file mode 100644 index 000000000000..6ef40a42a19d --- /dev/null +++ b/Zend/tests/autoload/class/trampoline_unregister_autoloader_from_list.phpt @@ -0,0 +1,46 @@ +--TEST-- +Unregister all class autoloaders by traversing the registered list: behavior with a trampoline +--FILE-- + +--EXPECT-- +array(2) { + [0]=> + array(2) { + [0]=> + object(TrampolineTest)#1 (0) { + } + [1]=> + string(11) "trampoline1" + } + [1]=> + array(2) { + [0]=> + object(TrampolineTest)#1 (0) { + } + [1]=> + string(11) "trampoline2" + } +} +array(0) { +} diff --git a/Zend/tests/autoload/class/un-register_take_effect_immediately.phpt b/Zend/tests/autoload/class/un-register_take_effect_immediately.phpt new file mode 100644 index 000000000000..2b66aaca247f --- /dev/null +++ b/Zend/tests/autoload/class/un-register_take_effect_immediately.phpt @@ -0,0 +1,38 @@ +--TEST-- +(Un)Registering autoloaders must take effect immidiately +--FILE-- + +--EXPECT-- +okey, done diff --git a/Zend/tests/autoload/class/unregister_autoloader.phpt b/Zend/tests/autoload/class/unregister_autoloader.phpt new file mode 100644 index 000000000000..e6110c7c844b --- /dev/null +++ b/Zend/tests/autoload/class/unregister_autoloader.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test autoload_unregister_class(): basic function behavior +--FILE-- + +--EXPECT-- +TestFunc1(TestClass) +TestFunc2(TestClass) +bool(false) +bool(true) +bool(false) +TestFunc2(TestClass) +bool(false) diff --git a/Zend/tests/autoload/class/unregister_autoloader_from_list.phpt b/Zend/tests/autoload/class/unregister_autoloader_from_list.phpt new file mode 100644 index 000000000000..1072abfe6c5b --- /dev/null +++ b/Zend/tests/autoload/class/unregister_autoloader_from_list.phpt @@ -0,0 +1,22 @@ +--TEST-- +Unregister all autoloaders by traversing the registered list +--FILE-- + +--EXPECT-- +array(0) { +} diff --git a/Zend/tests/autoload/class_maps/basic_test.phpt b/Zend/tests/autoload/class_maps/basic_test.phpt new file mode 100644 index 000000000000..ebc718b2d412 --- /dev/null +++ b/Zend/tests/autoload/class_maps/basic_test.phpt @@ -0,0 +1,23 @@ +--TEST-- +Check that assigned class map works +--FILE-- + $pathTo . "Foo.inc", + 'Bar' => $pathTo . "Bar.inc", +]; + +autoload_register_class_map($classes); + +$f = new Foo(); +var_dump($f); +$b = new Bar(); +var_dump($b); + +?> +--EXPECT-- +object(Foo)#1 (0) { +} +object(Bar)#2 (0) { +} diff --git a/Zend/tests/autoload/class_maps/check_map_is_valid.phpt b/Zend/tests/autoload/class_maps/check_map_is_valid.phpt new file mode 100644 index 000000000000..d31e049bcecd --- /dev/null +++ b/Zend/tests/autoload/class_maps/check_map_is_valid.phpt @@ -0,0 +1,48 @@ +--TEST-- +Check that assigned class map works +--FILE-- +getMessage(), PHP_EOL; + } +} + +$pathTo = __DIR__ . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR; +$map = [ + 'Foo' => $pathTo . "Foo.inc", + 'not a symbol name' => $pathTo . "Bar.inc", +]; +test_map($map); + +$map = [ + 'Foo' => $pathTo . "Foo.inc", + 0 => $pathTo . "Bar.inc", +]; +test_map($map); + +$map = [ + 'Foo' => 0, +]; +test_map($map); + +$map = [ + 'Foo' => "", +]; +test_map($map); + +$map = [ + 'Foo' => "Path\0hasNull", +]; +test_map($map); + +?> +--EXPECT-- +ValueError: autoload_register_class_map(): Argument #1 ($classes) key "not a symbol name" is not a valid class name +ValueError: autoload_register_class_map(): Argument #1 ($classes) must only have string keys +TypeError: autoload_register_class_map(): Argument #1 ($classes) path for class "Foo" must be of type string +ValueError: autoload_register_class_map(): Argument #1 ($classes) path for class "Foo" must not be empty +ValueError: autoload_register_class_map(): Argument #1 ($classes) path for class "Foo" must not contain null bytes diff --git a/Zend/tests/autoload/class_maps/classes/Bar.inc b/Zend/tests/autoload/class_maps/classes/Bar.inc new file mode 100644 index 000000000000..bd6b6f454a46 --- /dev/null +++ b/Zend/tests/autoload/class_maps/classes/Bar.inc @@ -0,0 +1,5 @@ +type == ZEND_INTERNAL_FUNCTION && + fcc.function_handler->internal_function.handler == zif_autoload_call_class) { + zend_argument_value_error(1, "must not be the autoload_call_class() function"); + RETURN_THROWS(); + } + + zend_autoload_register_class_loader(&fcc, prepend); +} + +static bool zend_check_map_is_valid(const HashTable *map) { + zend_string *name; + zval *zval_path; + + if (zend_hash_num_elements(map) == 0) { + zend_argument_must_not_be_empty_error(1); + return false; + } + + ZEND_HASH_FOREACH_STR_KEY_VAL(map, name, zval_path) { + if (!name) { + zend_argument_value_error(1, "must only have string keys", name ? ZSTR_VAL(name) : ""); + return false; + } + if (ZSTR_LEN(name) == 0 || !zend_is_valid_class_name(name)) { + zend_argument_value_error(1, "key \"%s\" is not a valid class name", name ? ZSTR_VAL(name) : ""); + return false; + } + if (Z_TYPE_P(zval_path) != IS_STRING) { + zend_argument_type_error(1, "path for class \"%s\" must be of type string", ZSTR_VAL(name)); + return false; + } + if (Z_STRLEN_P(zval_path) == 0) { + zend_argument_value_error(1, "path for class \"%s\" must not be empty", ZSTR_VAL(name)); + return false; + } + if (zend_str_has_nul_byte(Z_STR_P(zval_path))) { + zend_argument_value_error(1, "path for class \"%s\" must not contain null bytes", ZSTR_VAL(name)); + return false; + } + } ZEND_HASH_FOREACH_END(); + + return true; +} + +ZEND_FUNCTION(autoload_register_class_map) +{ + HashTable *class_map; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY_HT(class_map) + ZEND_PARSE_PARAMETERS_END(); + + if (UNEXPECTED(!zend_check_map_is_valid(class_map))) { + RETURN_THROWS(); + } + + zend_class_autoload_map = zend_array_dup(class_map); + zend_autoload = zend_perform_class_map_autoload; +} + +ZEND_FUNCTION(autoload_unregister_class) +{ + zend_fcall_info fci; + zend_fcall_info_cache fcc; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_FUNC_NO_TRAMPOLINE_FREE(fci, fcc) + ZEND_PARSE_PARAMETERS_END(); + + RETVAL_BOOL(zend_autoload_unregister_class_loader(&fcc)); + /* Release trampoline */ + zend_release_fcall_info_cache(&fcc); +} + +/* Try all registered class autoloader functions to load the requested class */ +ZEND_FUNCTION(autoload_call_class) +{ + zend_string *class_name; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &class_name) == FAILURE) { + RETURN_THROWS(); + } + + zend_string *lc_name = zend_string_tolower(class_name); + zend_perform_class_autoload(class_name, lc_name); + zend_string_release(lc_name); +} + +/* Return all registered class autoloader functions */ +ZEND_FUNCTION(autoload_list_class) { + ZEND_PARSE_PARAMETERS_NONE(); + + zend_autoload_fcc_map_to_callable_zval_map(return_value); +} + void zend_autoload_shutdown(void) { if (zend_class_autoload_functions) { @@ -163,4 +358,8 @@ void zend_autoload_shutdown(void) FREE_HASHTABLE(zend_class_autoload_functions); zend_class_autoload_functions = NULL; } + if (zend_class_autoload_map) { + zend_array_release(zend_class_autoload_map); + zend_class_autoload_map = NULL; + } } diff --git a/Zend/zend_autoload.h b/Zend/zend_autoload.h index fde4a4a82e9a..c7483abb1fd5 100644 --- a/Zend/zend_autoload.h +++ b/Zend/zend_autoload.h @@ -25,6 +25,7 @@ #include "zend.h" ZEND_API zend_class_entry *zend_perform_class_autoload(zend_string *class_name, zend_string *lc_name); +ZEND_API zend_class_entry *zend_perform_class_map_autoload(zend_string *class_name, zend_string *lc_name); ZEND_API void zend_autoload_register_class_loader(zend_fcall_info_cache *fcc, bool prepend); ZEND_API bool zend_autoload_unregister_class_loader(const zend_fcall_info_cache *fcc); ZEND_API void zend_autoload_fcc_map_to_callable_zval_map(zval *return_value); @@ -32,4 +33,10 @@ ZEND_API void zend_autoload_fcc_map_to_callable_zval_map(zval *return_value); ZEND_API void zend_autoload_clean_class_loaders(void); void zend_autoload_shutdown(void); +ZEND_FUNCTION(autoload_register_class); +ZEND_FUNCTION(autoload_register_class_map); +ZEND_FUNCTION(autoload_unregister_class); +ZEND_FUNCTION(autoload_call_class); +ZEND_FUNCTION(autoload_list_class); + #endif diff --git a/Zend/zend_builtin_functions.stub.php b/Zend/zend_builtin_functions.stub.php index 9b2267b531eb..50d594d62bbf 100644 --- a/Zend/zend_builtin_functions.stub.php +++ b/Zend/zend_builtin_functions.stub.php @@ -217,3 +217,13 @@ function gc_disable(): void {} * @refcount 1 */ function gc_status(): array {} + +function autoload_register_class(callable $callback, bool $prepend = false): void {} + +function autoload_register_class_map(array $classes): void {} + +function autoload_unregister_class(callable $callback): bool {} + +function autoload_call_class(string $class): void {} + +function autoload_list_class(): array {} diff --git a/Zend/zend_builtin_functions_arginfo.h b/Zend/zend_builtin_functions_arginfo.h index cb626ff430e6..d605c9d5b916 100644 --- a/Zend/zend_builtin_functions_arginfo.h +++ b/Zend/zend_builtin_functions_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit zend_builtin_functions.stub.php instead. - * Stub hash: 9b49f527064695c812cd204d9efc63c13681d942 */ + * Stub hash: aa235167ada4497f50840ba5c73434b3a59388fa */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_clone, 0, 1, IS_OBJECT, 0) ZEND_ARG_TYPE_INFO(0, object, IS_OBJECT, 0) @@ -233,6 +233,25 @@ ZEND_END_ARG_INFO() #define arginfo_gc_status arginfo_func_get_args +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_autoload_register_class, 0, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, prepend, _IS_BOOL, 0, "false") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_autoload_register_class_map, 0, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, classes, IS_ARRAY, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_autoload_unregister_class, 0, 1, _IS_BOOL, 0) + ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_autoload_call_class, 0, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, class, IS_STRING, 0) +ZEND_END_ARG_INFO() + +#define arginfo_autoload_list_class arginfo_func_get_args + ZEND_FRAMELESS_FUNCTION(property_exists, 2); static const zend_frameless_function_info frameless_function_infos_property_exists[] = { @@ -310,6 +329,11 @@ ZEND_FUNCTION(gc_enabled); ZEND_FUNCTION(gc_enable); ZEND_FUNCTION(gc_disable); ZEND_FUNCTION(gc_status); +ZEND_FUNCTION(autoload_register_class); +ZEND_FUNCTION(autoload_register_class_map); +ZEND_FUNCTION(autoload_unregister_class); +ZEND_FUNCTION(autoload_call_class); +ZEND_FUNCTION(autoload_list_class); static const zend_function_entry ext_functions[] = { ZEND_FE(clone, arginfo_clone) @@ -377,6 +401,11 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(gc_enable, arginfo_gc_enable) ZEND_FE(gc_disable, arginfo_gc_disable) ZEND_FE(gc_status, arginfo_gc_status) + ZEND_FE(autoload_register_class, arginfo_autoload_register_class) + ZEND_FE(autoload_register_class_map, arginfo_autoload_register_class_map) + ZEND_FE(autoload_unregister_class, arginfo_autoload_unregister_class) + ZEND_FE(autoload_call_class, arginfo_autoload_call_class) + ZEND_FE(autoload_list_class, arginfo_autoload_list_class) ZEND_FE_END }; diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index e705a1e303a2..56ef5039948e 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -340,20 +340,6 @@ PHP_FUNCTION(spl_autoload_extensions) } } /* }}} */ -/* {{{ Try all registered autoload function to load the requested class */ -PHP_FUNCTION(spl_autoload_call) -{ - zend_string *class_name; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &class_name) == FAILURE) { - RETURN_THROWS(); - } - - zend_string *lc_name = zend_string_tolower(class_name); - zend_perform_class_autoload(class_name, lc_name); - zend_string_release(lc_name); -} /* }}} */ - /* {{{ Register given function as autoloader */ PHP_FUNCTION(spl_autoload_register) { @@ -384,7 +370,7 @@ PHP_FUNCTION(spl_autoload_register) } if (fcc.function_handler->type == ZEND_INTERNAL_FUNCTION && - fcc.function_handler->internal_function.handler == zif_spl_autoload_call) { + fcc.function_handler->internal_function.handler == zif_autoload_call_class) { zend_argument_value_error(1, "must not be the spl_autoload_call() function"); RETURN_THROWS(); } @@ -427,14 +413,6 @@ PHP_FUNCTION(spl_autoload_unregister) zend_release_fcall_info_cache(&fcc); } /* }}} */ -/* {{{ Return all registered autoloader functions */ -PHP_FUNCTION(spl_autoload_functions) -{ - ZEND_PARSE_PARAMETERS_NONE(); - - zend_autoload_fcc_map_to_callable_zval_map(return_value); -} /* }}} */ - /* {{{ Return hash id for given object */ PHP_FUNCTION(spl_object_hash) { diff --git a/ext/spl/php_spl.stub.php b/ext/spl/php_spl.stub.php index d3b5d44f11d1..97f12fee3bd4 100644 --- a/ext/spl/php_spl.stub.php +++ b/ext/spl/php_spl.stub.php @@ -25,10 +25,12 @@ function class_uses($object_or_class, bool $autoload = true): array|false {} function spl_autoload(string $class, ?string $file_extensions = null): void {} +/** @alias autoload_call_class */ function spl_autoload_call(string $class): void {} function spl_autoload_extensions(?string $file_extensions = null): string {} +/** @alias autoload_list_class */ function spl_autoload_functions(): array {} function spl_autoload_register(?callable $callback = null, bool $throw = true, bool $prepend = false): bool {} diff --git a/ext/spl/php_spl_arginfo.h b/ext/spl/php_spl_arginfo.h index 8b0ea4b7245b..2e28cb7d2c33 100644 --- a/ext/spl/php_spl_arginfo.h +++ b/ext/spl/php_spl_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit php_spl.stub.php instead. - * Stub hash: 21ec2dcca99c85c90afcd319da76016a9f678dc2 */ + * Stub hash: e4e4c18b069f3a2d57fcbdd704bbc5d55ff06147 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_implements, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE) ZEND_ARG_INFO(0, object_or_class) @@ -65,9 +65,9 @@ ZEND_FUNCTION(class_implements); ZEND_FUNCTION(class_parents); ZEND_FUNCTION(class_uses); ZEND_FUNCTION(spl_autoload); -ZEND_FUNCTION(spl_autoload_call); +ZEND_FUNCTION(autoload_call_class); ZEND_FUNCTION(spl_autoload_extensions); -ZEND_FUNCTION(spl_autoload_functions); +ZEND_FUNCTION(autoload_list_class); ZEND_FUNCTION(spl_autoload_register); ZEND_FUNCTION(spl_autoload_unregister); ZEND_FUNCTION(spl_classes); @@ -82,9 +82,9 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(class_parents, arginfo_class_parents) ZEND_FE(class_uses, arginfo_class_uses) ZEND_FE(spl_autoload, arginfo_spl_autoload) - ZEND_FE(spl_autoload_call, arginfo_spl_autoload_call) + ZEND_RAW_FENTRY("spl_autoload_call", zif_autoload_call_class, arginfo_spl_autoload_call, 0, NULL, NULL) ZEND_FE(spl_autoload_extensions, arginfo_spl_autoload_extensions) - ZEND_FE(spl_autoload_functions, arginfo_spl_autoload_functions) + ZEND_RAW_FENTRY("spl_autoload_functions", zif_autoload_list_class, arginfo_spl_autoload_functions, 0, NULL, NULL) ZEND_FE(spl_autoload_register, arginfo_spl_autoload_register) ZEND_FE(spl_autoload_unregister, arginfo_spl_autoload_unregister) ZEND_FE(spl_classes, arginfo_spl_classes) diff --git a/ext/spl/tests/autoloading/bug40091.phpt b/ext/spl/tests/autoloading/bug40091.phpt deleted file mode 100644 index 3bb1bbf15238..000000000000 --- a/ext/spl/tests/autoloading/bug40091.phpt +++ /dev/null @@ -1,41 +0,0 @@ ---TEST-- -Bug #40091 (issue with spl_autoload_register() and 2 instances of the same class) ---FILE-- - ---EXPECT-- -Array -( - [0] => Array - ( - [0] => MyAutoloader Object - ( - ) - - [1] => autoload - ) - - [1] => Array - ( - [0] => MyAutoloader Object - ( - ) - - [1] => autoload - ) - -) diff --git a/ext/spl/tests/autoloading/bug44144.phpt b/ext/spl/tests/autoloading/bug44144.phpt deleted file mode 100644 index 7dbcf1e63671..000000000000 --- a/ext/spl/tests/autoloading/bug44144.phpt +++ /dev/null @@ -1,23 +0,0 @@ ---TEST-- -Bug #44144 (spl_autoload_functions() should return object instance when appropriate) ---FILE-- - ---EXPECTF-- -array(1) { - [0]=> - array(2) { - [0]=> - object(Foo)#%d (0) { - } - [1]=> - string(15) "nonstaticMethod" - } -} diff --git a/ext/spl/tests/autoloading/bug48023.phpt b/ext/spl/tests/autoloading/bug48023.phpt deleted file mode 100644 index e42e2f4f03cd..000000000000 --- a/ext/spl/tests/autoloading/bug48023.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -Bug #48023 (spl_autoload_register didn't addref closures) ---FILE-- - -===DONE=== ---EXPECTF-- -Fatal error: Uncaught Error: Class "Foo" not found in %s:%d -Stack trace: -#0 {main} - thrown in %s on line %d diff --git a/ext/spl/tests/autoloading/bug48493.phpt b/ext/spl/tests/autoloading/bug48493.phpt deleted file mode 100644 index d0be7f8ec71f..000000000000 --- a/ext/spl/tests/autoloading/bug48493.phpt +++ /dev/null @@ -1,26 +0,0 @@ ---TEST-- -SPL: Bug #48493 spl_autoload_unregister() can't handle prepended functions ---FILE-- - ---EXPECT-- -array(2) { - [0]=> - string(9) "autoload1" - [1]=> - string(9) "autoload2" -} -array(1) { - [0]=> - string(9) "autoload1" -} diff --git a/ext/spl/tests/autoloading/bug61697.phpt b/ext/spl/tests/autoloading/bug61697.phpt deleted file mode 100644 index 458bba66638b..000000000000 --- a/ext/spl/tests/autoloading/bug61697.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -Bug #61697 (spl_autoload_functions returns lambda functions incorrectly) ---FILE-- - ---EXPECT-- -Array -( -) diff --git a/ext/spl/tests/autoloading/bug71202.phpt b/ext/spl/tests/autoloading/bug71202.phpt index 84c9b609445f..2b66aaca247f 100644 --- a/ext/spl/tests/autoloading/bug71202.phpt +++ b/ext/spl/tests/autoloading/bug71202.phpt @@ -1,5 +1,5 @@ --TEST-- -Bug #71202 (Autoload function registered by another not activated immediately) +(Un)Registering autoloaders must take effect immidiately --FILE-- ---EXPECTF-- -Deprecated: spl_autoload_unregister(): Using spl_autoload_call() as a callback for spl_autoload_unregister() is deprecated, to remove all registered autoloaders, call spl_autoload_unregister() for all values returned from spl_autoload_functions() in %s on line %d - -Fatal error: Uncaught Error: Class "A" not found in %s:%d -Stack trace: -#0 {main} - thrown in %sbug71204.php on line %d diff --git a/ext/spl/tests/autoloading/bug74372.phpt b/ext/spl/tests/autoloading/bug74372.phpt index c2506009a584..a5c70c8faf1a 100644 --- a/ext/spl/tests/autoloading/bug74372.phpt +++ b/ext/spl/tests/autoloading/bug74372.phpt @@ -1,12 +1,12 @@ --TEST-- -Bug #74372: autoloading file with syntax error uses next autoloader, may hide parse error +Parse errors should be thrown if occuring from an autoloader --FILE-- ---EXPECT-- -11110 diff --git a/ext/spl/tests/autoloading/spl_autoload_003.phpt b/ext/spl/tests/autoloading/spl_autoload_003.phpt index 016bcf2394b6..29ab61f8858a 100644 --- a/ext/spl/tests/autoloading/spl_autoload_003.phpt +++ b/ext/spl/tests/autoloading/spl_autoload_003.phpt @@ -1,36 +1,28 @@ --TEST-- -SPL: spl_autoload() and friends ---INI-- -include_path=. +Exception thrown from within autoloading function --FILE-- getMessage() . "\n"; } diff --git a/ext/spl/tests/autoloading/spl_autoload_004.phpt b/ext/spl/tests/autoloading/spl_autoload_004.phpt deleted file mode 100644 index 8e1eafc37a5d..000000000000 --- a/ext/spl/tests/autoloading/spl_autoload_004.phpt +++ /dev/null @@ -1,40 +0,0 @@ ---TEST-- -SPL: spl_autoload() with static methods ---INI-- -include_path=. ---FILE-- - ---EXPECT-- -array(1) { - [0]=> - array(2) { - [0]=> - string(12) "MyAutoLoader" - [1]=> - string(8) "autoLoad" - } -} -MyAutoLoader::autoLoad(TestClass) -bool(false) diff --git a/ext/spl/tests/autoloading/spl_autoload_005.phpt b/ext/spl/tests/autoloading/spl_autoload_005.phpt deleted file mode 100644 index 0f2c5ed2c302..000000000000 --- a/ext/spl/tests/autoloading/spl_autoload_005.phpt +++ /dev/null @@ -1,49 +0,0 @@ ---TEST-- -SPL: spl_autoload() with methods ---INI-- -include_path=. ---FILE-- -getMessage() . \PHP_EOL; -} - -// and - -$myAutoLoader = new MyAutoLoader(); - -spl_autoload_register(array($myAutoLoader, 'autoLoad')); -spl_autoload_register(array($myAutoLoader, 'autoThrow')); - -try -{ - var_dump(class_exists("TestClass", true)); -} -catch(Exception $e) -{ - echo 'Exception: ' . $e->getMessage() . "\n"; -} - -?> ---EXPECT-- -spl_autoload_register(): Argument #1 ($callback) must be a valid callback or null, non-static method MyAutoLoader::autoLoad() cannot be called statically -MyAutoLoader::autoLoad(TestClass) -MyAutoLoader::autoThrow(TestClass) -Exception: Unavailable diff --git a/ext/spl/tests/autoloading/spl_autoload_006.phpt b/ext/spl/tests/autoloading/spl_autoload_006.phpt index 7db2b462ca36..c6903ad337b6 100644 --- a/ext/spl/tests/autoloading/spl_autoload_006.phpt +++ b/ext/spl/tests/autoloading/spl_autoload_006.phpt @@ -1,20 +1,17 @@ --TEST-- -SPL: spl_autoload() with static methods ---INI-- -include_path=. +Autoloader is a static method --FILE-- $func) if ($idx) echo "\n"; try { var_dump($func); - spl_autoload_register($func); + autoload_register_class($func); echo "ok\n"; } catch(\TypeError $e) { echo $e->getMessage() . \PHP_EOL; @@ -52,16 +52,16 @@ foreach($funcs as $idx => $func) ?> --EXPECTF-- string(22) "MyAutoLoader::notExist" -spl_autoload_register(): Argument #1 ($callback) must be a valid callback or null, class MyAutoLoader does not have a method "notExist" +autoload_register_class(): Argument #1 ($callback) must be a valid callback, class MyAutoLoader does not have a method "notExist" string(22) "MyAutoLoader::noAccess" -spl_autoload_register(): Argument #1 ($callback) must be a valid callback or null, cannot access protected method MyAutoLoader::noAccess() +autoload_register_class(): Argument #1 ($callback) must be a valid callback, cannot access protected method MyAutoLoader::noAccess() string(22) "MyAutoLoader::autoLoad" ok string(22) "MyAutoLoader::dynaLoad" -spl_autoload_register(): Argument #1 ($callback) must be a valid callback or null, non-static method MyAutoLoader::dynaLoad() cannot be called statically +autoload_register_class(): Argument #1 ($callback) must be a valid callback, non-static method MyAutoLoader::dynaLoad() cannot be called statically array(2) { [0]=> @@ -69,7 +69,7 @@ array(2) { [1]=> string(8) "notExist" } -spl_autoload_register(): Argument #1 ($callback) must be a valid callback or null, class MyAutoLoader does not have a method "notExist" +autoload_register_class(): Argument #1 ($callback) must be a valid callback, class MyAutoLoader does not have a method "notExist" array(2) { [0]=> @@ -77,7 +77,7 @@ array(2) { [1]=> string(8) "noAccess" } -spl_autoload_register(): Argument #1 ($callback) must be a valid callback or null, cannot access protected method MyAutoLoader::noAccess() +autoload_register_class(): Argument #1 ($callback) must be a valid callback, cannot access protected method MyAutoLoader::noAccess() array(2) { [0]=> @@ -93,7 +93,7 @@ array(2) { [1]=> string(8) "dynaLoad" } -spl_autoload_register(): Argument #1 ($callback) must be a valid callback or null, non-static method MyAutoLoader::dynaLoad() cannot be called statically +autoload_register_class(): Argument #1 ($callback) must be a valid callback, non-static method MyAutoLoader::dynaLoad() cannot be called statically array(2) { [0]=> @@ -102,7 +102,7 @@ array(2) { [1]=> string(8) "notExist" } -spl_autoload_register(): Argument #1 ($callback) must be a valid callback or null, class MyAutoLoader does not have a method "notExist" +autoload_register_class(): Argument #1 ($callback) must be a valid callback, class MyAutoLoader does not have a method "notExist" array(2) { [0]=> @@ -111,7 +111,7 @@ array(2) { [1]=> string(8) "noAccess" } -spl_autoload_register(): Argument #1 ($callback) must be a valid callback or null, cannot access protected method MyAutoLoader::noAccess() +autoload_register_class(): Argument #1 ($callback) must be a valid callback, cannot access protected method MyAutoLoader::noAccess() array(2) { [0]=> diff --git a/ext/spl/tests/autoloading/spl_autoload_008.phpt b/ext/spl/tests/autoloading/spl_autoload_008.phpt index 738c691ddfe9..e1baf602e96f 100644 --- a/ext/spl/tests/autoloading/spl_autoload_008.phpt +++ b/ext/spl/tests/autoloading/spl_autoload_008.phpt @@ -1,7 +1,5 @@ --TEST-- -SPL: spl_autoload() with exceptions ---INI-- -include_path=. +Exceptions during autoloading --FILE-- $func) var_dump($func); try { - spl_autoload_register($func); + autoload_register_class($func); } catch (TypeError $e) { echo get_class($e) . ': ' . $e->getMessage() . \PHP_EOL; - var_dump(count(spl_autoload_functions())); + var_dump(count(autoload_list_class())); continue; } - if (count(spl_autoload_functions())) { + if (count(autoload_list_class())) { echo "registered\n"; try { @@ -61,8 +59,8 @@ foreach($funcs as $idx => $func) } } - spl_autoload_unregister($func); - var_dump(count(spl_autoload_functions())); + autoload_unregister_class($func); + var_dump(count(autoload_list_class())); } ?> @@ -81,7 +79,7 @@ Exception: Bla int(0) ====2==== string(22) "MyAutoLoader::dynaLoad" -TypeError: spl_autoload_register(): Argument #1 ($callback) must be a valid callback or null, non-static method MyAutoLoader::dynaLoad() cannot be called statically +TypeError: autoload_register_class(): Argument #1 ($callback) must be a valid callback, non-static method MyAutoLoader::dynaLoad() cannot be called statically int(0) ====3==== array(2) { @@ -101,7 +99,7 @@ array(2) { [1]=> string(8) "dynaLoad" } -TypeError: spl_autoload_register(): Argument #1 ($callback) must be a valid callback or null, non-static method MyAutoLoader::dynaLoad() cannot be called statically +TypeError: autoload_register_class(): Argument #1 ($callback) must be a valid callback, non-static method MyAutoLoader::dynaLoad() cannot be called statically int(0) ====5==== array(2) { diff --git a/ext/spl/tests/autoloading/spl_autoload_009.phpt b/ext/spl/tests/autoloading/spl_autoload_009.phpt deleted file mode 100644 index f12fd0af7e70..000000000000 --- a/ext/spl/tests/autoloading/spl_autoload_009.phpt +++ /dev/null @@ -1,23 +0,0 @@ ---TEST-- -SPL: spl_autoload() and friends ---INI-- -include_path=. ---FILE-- - ---EXPECTF-- -%stestclass.inc -%stestclass.class.inc -bool(true) diff --git a/ext/spl/tests/autoloading/spl_autoload_010.phpt b/ext/spl/tests/autoloading/spl_autoload_010.phpt deleted file mode 100644 index 3b0754d8dfa9..000000000000 --- a/ext/spl/tests/autoloading/spl_autoload_010.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -SPL: spl_autoload() and prepend ---INI-- -include_path=. ---FILE-- - $name\n"; -} -function autoloadB($name) { - echo "B -> $name\n"; -} -function autoloadC($name) { - echo "C -> $name\n"; - class C{} -} - -spl_autoload_register('autoloadA'); -spl_autoload_register('autoloadB', true, true); -spl_autoload_register('autoloadC'); - -new C; -?> ---EXPECT-- -B -> C -A -> C -C -> C diff --git a/ext/spl/tests/autoloading/spl_autoload_011.phpt b/ext/spl/tests/autoloading/spl_autoload_011.phpt index 771726ee56d8..2f667971de90 100644 --- a/ext/spl/tests/autoloading/spl_autoload_011.phpt +++ b/ext/spl/tests/autoloading/spl_autoload_011.phpt @@ -1,7 +1,5 @@ --TEST-- -SPL: spl_autoload() and object freed ---INI-- -include_path=. +Destructor call of autoloader when object freed --FILE-- var = 2; -spl_autoload_register(array($a, 'autoload')); +autoload_register_class(array($a, 'autoload')); unset($a); var_dump(class_exists("C", true)); diff --git a/ext/spl/tests/autoloading/spl_autoload_012.phpt b/ext/spl/tests/autoloading/spl_autoload_012.phpt index 218d3e800ff2..45ef5599f7cc 100644 --- a/ext/spl/tests/autoloading/spl_autoload_012.phpt +++ b/ext/spl/tests/autoloading/spl_autoload_012.phpt @@ -1,22 +1,20 @@ --TEST-- -SPL: spl_autoload() capturing multiple Exceptions in __autoload +Capturing multiple Exceptions during autoloading --FILE-- dir = $dir; - } - public function __invoke($class) { - var_dump("{$this->dir}/$class.php"); - } -} - -$al1 = new Autoloader('d1'); -$al2 = new Autoloader('d2'); - -spl_autoload_register($closure); -spl_autoload_register($al1); -spl_autoload_register($al2); - -var_dump(spl_autoload_functions()); - -?> ---EXPECTF-- -array(3) { - [0]=> - object(Closure)#%d (4) { - ["name"]=> - string(%d) "{closure:%s:%d}" - ["file"]=> - string(%d) "%s" - ["line"]=> - int(%d) - ["parameter"]=> - array(1) { - ["$class"]=> - string(10) "" - } - } - [1]=> - object(Autoloader)#%d (1) { - ["dir":"Autoloader":private]=> - string(2) "d1" - } - [2]=> - object(Autoloader)#%d (1) { - ["dir":"Autoloader":private]=> - string(2) "d2" - } -} diff --git a/ext/spl/tests/autoloading/spl_autoload_014.phpt b/ext/spl/tests/autoloading/spl_autoload_014.phpt deleted file mode 100644 index 3c7cc38f63e3..000000000000 --- a/ext/spl/tests/autoloading/spl_autoload_014.phpt +++ /dev/null @@ -1,45 +0,0 @@ ---TEST-- -SPL: spl_autoload_unregister() with closures and invocables ---FILE-- -dir = $dir; - } - public function __invoke($class) { - echo ("Autoloader('{$this->dir}') called with $class\n"); - } -} - -class WorkingAutoloader { - public function __invoke($class) { - echo ("WorkingAutoloader() called with $class\n"); - eval("class $class { }"); - } -} - -$al1 = new Autoloader('d1'); -$al2 = new WorkingAutoloader('d2'); - -spl_autoload_register($closure); -spl_autoload_register($al1); -spl_autoload_register($al2); - -$x = new TestX; - -spl_autoload_unregister($closure); -spl_autoload_unregister($al1); - -$y = new TestY; - -?> ---EXPECT-- -closure called with class TestX -Autoloader('d1') called with TestX -WorkingAutoloader() called with TestX -WorkingAutoloader() called with TestY diff --git a/ext/spl/tests/autoloading/spl_autoload_bug48541.phpt b/ext/spl/tests/autoloading/spl_autoload_bug48541.phpt deleted file mode 100644 index acdf36aa71d1..000000000000 --- a/ext/spl/tests/autoloading/spl_autoload_bug48541.phpt +++ /dev/null @@ -1,37 +0,0 @@ ---TEST-- -SPL: spl_autoload_register() Bug #48541: registering multiple closures fails with memleaks ---FILE-- -getClosure(); -$b = function ($class) { - eval('class ' . $class . '{function __construct(){echo "foo\n";}}'); - echo "b called\n"; -}; -spl_autoload_register($a); -spl_autoload_register($a2); -spl_autoload_register($b); - -$c = $a; -$c2 = $a2; -spl_autoload_register($c); -spl_autoload_register($c2); -$c = new foo; -?> ---EXPECT-- -a called -a2 called -b called -foo diff --git a/ext/spl/tests/autoloading/spl_autoload_call_basic.phpt b/ext/spl/tests/autoloading/spl_autoload_call_basic.phpt deleted file mode 100644 index 2bd65c22be4b..000000000000 --- a/ext/spl/tests/autoloading/spl_autoload_call_basic.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -spl_autoload_call() function - basic test for spl_autoload_call() ---CREDITS-- -Jean-Marc Fontaine -# Alter Way Contribution Day 2011 ---FILE-- - ---EXPECTF-- -%stestclass.class.inc -bool(true) diff --git a/ext/spl/tests/autoloading/spl_autoload_called_scope.phpt b/ext/spl/tests/autoloading/spl_autoload_called_scope.phpt index 23f2e84d952b..d19fc3d9c91d 100644 --- a/ext/spl/tests/autoloading/spl_autoload_called_scope.phpt +++ b/ext/spl/tests/autoloading/spl_autoload_called_scope.phpt @@ -1,11 +1,11 @@ --TEST-- -SPL autoloader should not do anything magic with called scope +Autoloader should not do anything magic with called scope --FILE--