xref: /PHP-7.4/ext/spl/tests/spl_autoload_013.phpt (revision d679f022)
1--TEST--
2SPL: spl_autoload_functions() with closures and invokables
3--FILE--
4<?php
5$closure = function($class) {
6  echo "a called\n";
7};
8
9class Autoloader {
10  private $dir;
11  public function __construct($dir) {
12    $this->dir = $dir;
13  }
14  public function __invoke($class) {
15    var_dump("{$this->dir}/$class.php");
16  }
17}
18
19$al1 = new Autoloader('d1');
20$al2 = new Autoloader('d2');
21
22spl_autoload_register($closure);
23spl_autoload_register($al1);
24spl_autoload_register($al2);
25
26var_dump(spl_autoload_functions());
27
28?>
29===DONE===
30--EXPECTF--
31array(3) {
32  [0]=>
33  object(Closure)#%d (1) {
34    ["parameter"]=>
35    array(1) {
36      ["$class"]=>
37      string(10) "<required>"
38    }
39  }
40  [1]=>
41  object(Autoloader)#%d (1) {
42    ["dir":"Autoloader":private]=>
43    string(2) "d1"
44  }
45  [2]=>
46  object(Autoloader)#%d (1) {
47    ["dir":"Autoloader":private]=>
48    string(2) "d2"
49  }
50}
51===DONE===
52