xref: /PHP-5.5/ext/spl/tests/spl_autoload_014.phpt (revision b4a43d0d)
1--TEST--
2SPL: spl_autoload_unregister() with closures and invokables
3--FILE--
4<?php
5$closure = function($class) {
6  echo "closure called with class $class\n";
7};
8
9class Autoloader {
10  private $dir;
11  public function __construct($dir) {
12    $this->dir = $dir;
13  }
14  public function __invoke($class) {
15    echo ("Autoloader('{$this->dir}') called with $class\n");
16  }
17}
18
19class WorkingAutoloader {
20  public function __invoke($class) {
21    echo ("WorkingAutoloader() called with $class\n");
22    eval("class $class { }");
23  }
24}
25
26$al1 = new Autoloader('d1');
27$al2 = new WorkingAutoloader('d2');
28
29spl_autoload_register($closure);
30spl_autoload_register($al1);
31spl_autoload_register($al2);
32
33$x = new TestX;
34
35spl_autoload_unregister($closure);
36spl_autoload_unregister($al1);
37
38$y = new TestY;
39
40?>
41===DONE===
42--EXPECT--
43closure called with class TestX
44Autoloader('d1') called with TestX
45WorkingAutoloader() called with TestX
46WorkingAutoloader() called with TestY
47===DONE===