reference/spl/functions/spl-autoload-register.xml
d4b762e22e53d959330b53674b73841cfff4dddf
...
...
@@ -9,9 +9,9 @@
9
9
&reftitle.description;
10
10
<methodsynopsis>
11
11
<type>bool</type><methodname>spl_autoload_register</methodname>
12
-
<methodparam choice="opt"><type>callable</type><parameter>autoload_function</parameter></methodparam>
13
-
<methodparam choice="opt"><type>bool</type><parameter>throw</parameter><initializer>true</initializer></methodparam>
14
-
<methodparam choice="opt"><type>bool</type><parameter>prepend</parameter><initializer>false</initializer></methodparam>
12
+
<methodparam choice="opt"><type class="union"><type>callable</type><type>null</type></type><parameter>callback</parameter><initializer>&null;</initializer></methodparam>
13
+
<methodparam choice="opt"><type>bool</type><parameter>throw</parameter><initializer>&true;</initializer></methodparam>
14
+
<methodparam choice="opt"><type>bool</type><parameter>prepend</parameter><initializer>&false;</initializer></methodparam>
15
15
</methodsynopsis>
16
16
<para>
17
17
Register a function with the spl provided __autoload queue. If the queue
...
...
@@ -38,13 +38,21 @@
38
38
<para>
39
39
<variablelist>
40
40
<varlistentry>
41
-
<term><parameter>autoload_function</parameter></term>
41
+
<term><parameter>callback</parameter></term>
42
42
<listitem>
43
43
<para>
44
44
The autoload function being registered.
45
-
If no parameter is provided, then the default implementation of
45
+
If &null;, then the default implementation of
46
46
<function>spl_autoload</function> will be registered.
47
47
</para>
48
+
<methodsynopsis>
49
+
<type>void</type><methodname><replaceable>callback</replaceable></methodname>
50
+
<methodparam><type>string</type><parameter>class</parameter></methodparam>
51
+
</methodsynopsis>
52
+
<para>
53
+
The <parameter>class</parameter> will not contain the leading
54
+
backslash of a fully-qualified identifier.
55
+
</para>
48
56
</listitem>
49
57
</varlistentry>
50
58
<varlistentry>
...
...
@@ -53,16 +61,24 @@
53
61
<para>
54
62
This parameter specifies whether
55
63
<function>spl_autoload_register</function> should throw
56
-
exceptions when the <parameter>autoload_function</parameter>
64
+
exceptions when the <parameter>callback</parameter>
57
65
cannot be registered.
58
66
</para>
67
+
<warning>
68
+
<para>
69
+
This parameter is ignored as of PHP 8.0.0, and a notice will be
70
+
emitted if set to &false;. <function>spl_autoload_register</function>
71
+
will now always throw a <classname>TypeError</classname> on invalid
72
+
arguments.
73
+
</para>
74
+
</warning>
59
75
</listitem>
60
76
</varlistentry>
61
77
<varlistentry>
62
78
<term><parameter>prepend</parameter></term>
63
79
<listitem>
64
80
<para>
65
-
If true, <function>spl_autoload_register</function> will prepend
81
+
If &true;, <function>spl_autoload_register</function> will prepend
66
82
the autoloader on the autoload queue instead of appending it.
67
83
</para>
68
84
</listitem>
...
...
@@ -91,15 +107,9 @@
91
107
</thead>
92
108
<tbody>
93
109
<row>
94
-
<entry>5.3.0</entry>
95
-
<entry>
96
-
Namespaces support was introduced.
97
-
</entry>
98
-
</row>
99
-
<row>
100
-
<entry>5.3.0</entry>
110
+
<entry>8.0.0</entry>
101
111
<entry>
102
-
The <parameter>prepend</parameter> parameter was added.
112
+
<parameter>callback</parameter> is now nullable.
103
113
</entry>
104
114
</row>
105
115
</tbody>
...
...
@@ -127,7 +137,7 @@ function my_autoloader($class) {
127
137

128
138
spl_autoload_register('my_autoloader');
129
139

130
-
// Or, using an anonymous function as of PHP 5.3.0
140
+
// Or, using an anonymous function
131
141
spl_autoload_register(function ($class) {
132
142
include 'classes/' . $class . '.class.php';
133
143
});
...
...
@@ -145,12 +155,12 @@ spl_autoload_register(function ($class) {
145
155
namespace Foobar;
146
156

147
157
class Foo {
148
-
static public function test($name) {
149
-
print '[['. $name .']]';
158
+
static public function test($class) {
159
+
print '[['. $class .']]';
150
160
}
151
161
}
152
162

153
-
spl_autoload_register(__NAMESPACE__ .'\Foo::test'); // As of PHP 5.3.0
163
+
spl_autoload_register(__NAMESPACE__ .'\Foo::test');
154
164

155
165
new InexistentClass;
156
166

...
...
@@ -165,6 +175,34 @@ Fatal error: Class 'Foobar\InexistentClass' not found in ...
165
175
]]>
166
176
</screen>
167
177
</example>
178
+
<example>
179
+
<title>The identifier will be provided without the leading backslash</title>
180
+
<programlisting role="php">
181
+
<![CDATA[
182
+
<?php
183
+

184
+
spl_autoload_register(static function ($class) {
185
+
var_dump($class);
186
+
});
187
+

188
+
class_exists('RelativeName');
189
+
class_exists('RelativeName\\WithNamespace');
190
+
class_exists('\\AbsoluteName');
191
+
class_exists('\\AbsoluteName\\WithNamespace');
192
+

193
+
?>
194
+
]]>
195
+
</programlisting>
196
+
&example.outputs;
197
+
<screen>
198
+
<![CDATA[
199
+
string(12) "RelativeName"
200
+
string(26) "RelativeName\WithNamespace"
201
+
string(12) "AbsoluteName"
202
+
string(26) "AbsoluteName\WithNamespace"
203
+
]]>
204
+
</screen>
205
+
</example>
168
206
</para>
169
207
</refsect1>
170
208
...
...
@@ -178,7 +216,6 @@ Fatal error: Class 'Foobar\InexistentClass' not found in ...
178
216
</refsect1>
179
217

180
218
</refentry>
181
-

182
219
<!-- Keep this comment at the end of the file
183
220
Local variables:
184
221
mode: sgml
185
222