spl_autoload_014.phpt 940 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. --TEST--
  2. SPL: spl_autoload_unregister() with closures and invocables
  3. --FILE--
  4. <?php
  5. $closure = function($class) {
  6. echo "closure called with class $class\n";
  7. };
  8. class Autoloader {
  9. private $dir;
  10. public function __construct($dir) {
  11. $this->dir = $dir;
  12. }
  13. public function __invoke($class) {
  14. echo ("Autoloader('{$this->dir}') called with $class\n");
  15. }
  16. }
  17. class WorkingAutoloader {
  18. public function __invoke($class) {
  19. echo ("WorkingAutoloader() called with $class\n");
  20. eval("class $class { }");
  21. }
  22. }
  23. $al1 = new Autoloader('d1');
  24. $al2 = new WorkingAutoloader('d2');
  25. spl_autoload_register($closure);
  26. spl_autoload_register($al1);
  27. spl_autoload_register($al2);
  28. $x = new TestX;
  29. spl_autoload_unregister($closure);
  30. spl_autoload_unregister($al1);
  31. $y = new TestY;
  32. ?>
  33. --EXPECT--
  34. closure called with class TestX
  35. Autoloader('d1') called with TestX
  36. WorkingAutoloader() called with TestX
  37. WorkingAutoloader() called with TestY