/src/php-src/ext/spl/php_spl.c
Line | Count | Source |
1 | | /* |
2 | | +----------------------------------------------------------------------+ |
3 | | | Copyright (c) The PHP Group | |
4 | | +----------------------------------------------------------------------+ |
5 | | | This source file is subject to version 3.01 of the PHP license, | |
6 | | | that is bundled with this package in the file LICENSE, and is | |
7 | | | available through the world-wide-web at the following url: | |
8 | | | https://www.php.net/license/3_01.txt | |
9 | | | If you did not receive a copy of the PHP license and are unable to | |
10 | | | obtain it through the world-wide-web, please send a note to | |
11 | | | license@php.net so we can mail you a copy immediately. | |
12 | | +----------------------------------------------------------------------+ |
13 | | | Authors: Marcus Boerger <helly@php.net> | |
14 | | +----------------------------------------------------------------------+ |
15 | | */ |
16 | | |
17 | | #ifdef HAVE_CONFIG_H |
18 | | #include <config.h> |
19 | | #endif |
20 | | |
21 | | #include "php.h" |
22 | | #include "php_main.h" |
23 | | #include "ext/standard/info.h" |
24 | | #include "php_spl.h" |
25 | | #include "php_spl_arginfo.h" |
26 | | #include "spl_functions.h" |
27 | | #include "spl_array.h" |
28 | | #include "spl_directory.h" |
29 | | #include "spl_iterators.h" |
30 | | #include "spl_exceptions.h" |
31 | | #include "spl_observer.h" |
32 | | #include "spl_dllist.h" |
33 | | #include "spl_fixedarray.h" |
34 | | #include "spl_heap.h" |
35 | | #include "zend_autoload.h" |
36 | | #include "zend_exceptions.h" |
37 | | #include "zend_interfaces.h" |
38 | | |
39 | | ZEND_TLS zend_string *spl_autoload_extensions; |
40 | | |
41 | 0 | #define SPL_DEFAULT_FILE_EXTENSIONS ".inc,.php" |
42 | | |
43 | | static zend_class_entry * spl_find_ce_by_name(zend_string *name, bool autoload) |
44 | 0 | { |
45 | 0 | zend_class_entry *ce; |
46 | |
|
47 | 0 | if (!autoload) { |
48 | 0 | zend_string *lc_name = zend_string_tolower(name); |
49 | |
|
50 | 0 | ce = zend_hash_find_ptr(EG(class_table), lc_name); |
51 | 0 | zend_string_release(lc_name); |
52 | 0 | } else { |
53 | 0 | ce = zend_lookup_class(name); |
54 | 0 | } |
55 | 0 | if (ce == NULL) { |
56 | 0 | php_error_docref(NULL, E_WARNING, "Class %s does not exist%s", ZSTR_VAL(name), autoload ? " and could not be loaded" : ""); |
57 | 0 | return NULL; |
58 | 0 | } |
59 | | |
60 | 0 | return ce; |
61 | 0 | } |
62 | | |
63 | | /* {{{ Return an array containing the names of all parent classes */ |
64 | | PHP_FUNCTION(class_parents) |
65 | 0 | { |
66 | 0 | zval *obj; |
67 | 0 | zend_class_entry *parent_class, *ce; |
68 | 0 | bool autoload = true; |
69 | | |
70 | | /* We do not use Z_PARAM_OBJ_OR_STR here to be able to exclude int, float, and bool which are bogus class names */ |
71 | 0 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|b", &obj, &autoload) == FAILURE) { |
72 | 0 | RETURN_THROWS(); |
73 | 0 | } |
74 | | |
75 | 0 | if (Z_TYPE_P(obj) != IS_OBJECT && Z_TYPE_P(obj) != IS_STRING) { |
76 | 0 | zend_argument_type_error(1, "must be of type object|string, %s given", zend_zval_value_name(obj)); |
77 | 0 | RETURN_THROWS(); |
78 | 0 | } |
79 | | |
80 | 0 | if (Z_TYPE_P(obj) == IS_STRING) { |
81 | 0 | if (NULL == (ce = spl_find_ce_by_name(Z_STR_P(obj), autoload))) { |
82 | 0 | RETURN_FALSE; |
83 | 0 | } |
84 | 0 | } else { |
85 | 0 | ce = Z_OBJCE_P(obj); |
86 | 0 | } |
87 | | |
88 | 0 | array_init(return_value); |
89 | 0 | parent_class = ce->parent; |
90 | 0 | while (parent_class) { |
91 | 0 | spl_add_class_name(return_value, parent_class, 0, 0); |
92 | 0 | parent_class = parent_class->parent; |
93 | 0 | } |
94 | 0 | } |
95 | | /* }}} */ |
96 | | |
97 | | /* {{{ Return all classes and interfaces implemented by SPL */ |
98 | | PHP_FUNCTION(class_implements) |
99 | 0 | { |
100 | 0 | zval *obj; |
101 | 0 | bool autoload = true; |
102 | 0 | zend_class_entry *ce; |
103 | | |
104 | | /* We do not use Z_PARAM_OBJ_OR_STR here to be able to exclude int, float, and bool which are bogus class names */ |
105 | 0 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|b", &obj, &autoload) == FAILURE) { |
106 | 0 | RETURN_THROWS(); |
107 | 0 | } |
108 | 0 | if (Z_TYPE_P(obj) != IS_OBJECT && Z_TYPE_P(obj) != IS_STRING) { |
109 | 0 | zend_argument_type_error(1, "must be of type object|string, %s given", zend_zval_value_name(obj)); |
110 | 0 | RETURN_THROWS(); |
111 | 0 | } |
112 | | |
113 | 0 | if (Z_TYPE_P(obj) == IS_STRING) { |
114 | 0 | if (NULL == (ce = spl_find_ce_by_name(Z_STR_P(obj), autoload))) { |
115 | 0 | RETURN_FALSE; |
116 | 0 | } |
117 | 0 | } else { |
118 | 0 | ce = Z_OBJCE_P(obj); |
119 | 0 | } |
120 | | |
121 | 0 | array_init(return_value); |
122 | 0 | spl_add_interfaces(return_value, ce, 1, ZEND_ACC_INTERFACE); |
123 | 0 | } |
124 | | /* }}} */ |
125 | | |
126 | | /* {{{ Return all traits used by a class. */ |
127 | | PHP_FUNCTION(class_uses) |
128 | 0 | { |
129 | 0 | zval *obj; |
130 | 0 | bool autoload = true; |
131 | 0 | zend_class_entry *ce; |
132 | | |
133 | | /* We do not use Z_PARAM_OBJ_OR_STR here to be able to exclude int, float, and bool which are bogus class names */ |
134 | 0 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|b", &obj, &autoload) == FAILURE) { |
135 | 0 | RETURN_THROWS(); |
136 | 0 | } |
137 | 0 | if (Z_TYPE_P(obj) != IS_OBJECT && Z_TYPE_P(obj) != IS_STRING) { |
138 | 0 | zend_argument_type_error(1, "must be of type object|string, %s given", zend_zval_value_name(obj)); |
139 | 0 | RETURN_THROWS(); |
140 | 0 | } |
141 | | |
142 | 0 | if (Z_TYPE_P(obj) == IS_STRING) { |
143 | 0 | if (NULL == (ce = spl_find_ce_by_name(Z_STR_P(obj), autoload))) { |
144 | 0 | RETURN_FALSE; |
145 | 0 | } |
146 | 0 | } else { |
147 | 0 | ce = Z_OBJCE_P(obj); |
148 | 0 | } |
149 | | |
150 | 0 | array_init(return_value); |
151 | 0 | spl_add_traits(return_value, ce, 1, ZEND_ACC_TRAIT); |
152 | 0 | } |
153 | | /* }}} */ |
154 | | |
155 | | #define SPL_ADD_CLASS(class_name, z_list, sub, allow, ce_flags) \ |
156 | 440 | spl_add_classes(spl_ce_ ## class_name, z_list, sub, allow, ce_flags) |
157 | | |
158 | | #define SPL_LIST_CLASSES(z_list, sub, allow, ce_flags) \ |
159 | 8 | SPL_ADD_CLASS(AppendIterator, z_list, sub, allow, ce_flags); \ |
160 | 8 | SPL_ADD_CLASS(ArrayIterator, z_list, sub, allow, ce_flags); \ |
161 | 8 | SPL_ADD_CLASS(ArrayObject, z_list, sub, allow, ce_flags); \ |
162 | 8 | SPL_ADD_CLASS(BadFunctionCallException, z_list, sub, allow, ce_flags); \ |
163 | 8 | SPL_ADD_CLASS(BadMethodCallException, z_list, sub, allow, ce_flags); \ |
164 | 8 | SPL_ADD_CLASS(CachingIterator, z_list, sub, allow, ce_flags); \ |
165 | 8 | SPL_ADD_CLASS(CallbackFilterIterator, z_list, sub, allow, ce_flags); \ |
166 | 8 | SPL_ADD_CLASS(DirectoryIterator, z_list, sub, allow, ce_flags); \ |
167 | 8 | SPL_ADD_CLASS(DomainException, z_list, sub, allow, ce_flags); \ |
168 | 8 | SPL_ADD_CLASS(EmptyIterator, z_list, sub, allow, ce_flags); \ |
169 | 8 | SPL_ADD_CLASS(FilesystemIterator, z_list, sub, allow, ce_flags); \ |
170 | 8 | SPL_ADD_CLASS(FilterIterator, z_list, sub, allow, ce_flags); \ |
171 | 8 | SPL_ADD_CLASS(GlobIterator, z_list, sub, allow, ce_flags); \ |
172 | 8 | SPL_ADD_CLASS(InfiniteIterator, z_list, sub, allow, ce_flags); \ |
173 | 8 | SPL_ADD_CLASS(InvalidArgumentException, z_list, sub, allow, ce_flags); \ |
174 | 8 | SPL_ADD_CLASS(IteratorIterator, z_list, sub, allow, ce_flags); \ |
175 | 8 | SPL_ADD_CLASS(LengthException, z_list, sub, allow, ce_flags); \ |
176 | 8 | SPL_ADD_CLASS(LimitIterator, z_list, sub, allow, ce_flags); \ |
177 | 8 | SPL_ADD_CLASS(LogicException, z_list, sub, allow, ce_flags); \ |
178 | 8 | SPL_ADD_CLASS(MultipleIterator, z_list, sub, allow, ce_flags); \ |
179 | 8 | SPL_ADD_CLASS(NoRewindIterator, z_list, sub, allow, ce_flags); \ |
180 | 8 | SPL_ADD_CLASS(OuterIterator, z_list, sub, allow, ce_flags); \ |
181 | 8 | SPL_ADD_CLASS(OutOfBoundsException, z_list, sub, allow, ce_flags); \ |
182 | 8 | SPL_ADD_CLASS(OutOfRangeException, z_list, sub, allow, ce_flags); \ |
183 | 8 | SPL_ADD_CLASS(OverflowException, z_list, sub, allow, ce_flags); \ |
184 | 8 | SPL_ADD_CLASS(ParentIterator, z_list, sub, allow, ce_flags); \ |
185 | 8 | SPL_ADD_CLASS(RangeException, z_list, sub, allow, ce_flags); \ |
186 | 8 | SPL_ADD_CLASS(RecursiveArrayIterator, z_list, sub, allow, ce_flags); \ |
187 | 8 | SPL_ADD_CLASS(RecursiveCachingIterator, z_list, sub, allow, ce_flags); \ |
188 | 8 | SPL_ADD_CLASS(RecursiveCallbackFilterIterator, z_list, sub, allow, ce_flags); \ |
189 | 8 | SPL_ADD_CLASS(RecursiveDirectoryIterator, z_list, sub, allow, ce_flags); \ |
190 | 8 | SPL_ADD_CLASS(RecursiveFilterIterator, z_list, sub, allow, ce_flags); \ |
191 | 8 | SPL_ADD_CLASS(RecursiveIterator, z_list, sub, allow, ce_flags); \ |
192 | 8 | SPL_ADD_CLASS(RecursiveIteratorIterator, z_list, sub, allow, ce_flags); \ |
193 | 8 | SPL_ADD_CLASS(RecursiveRegexIterator, z_list, sub, allow, ce_flags); \ |
194 | 8 | SPL_ADD_CLASS(RecursiveTreeIterator, z_list, sub, allow, ce_flags); \ |
195 | 8 | SPL_ADD_CLASS(RegexIterator, z_list, sub, allow, ce_flags); \ |
196 | 8 | SPL_ADD_CLASS(RuntimeException, z_list, sub, allow, ce_flags); \ |
197 | 8 | SPL_ADD_CLASS(SeekableIterator, z_list, sub, allow, ce_flags); \ |
198 | 8 | SPL_ADD_CLASS(SplDoublyLinkedList, z_list, sub, allow, ce_flags); \ |
199 | 8 | SPL_ADD_CLASS(SplFileInfo, z_list, sub, allow, ce_flags); \ |
200 | 8 | SPL_ADD_CLASS(SplFileObject, z_list, sub, allow, ce_flags); \ |
201 | 8 | SPL_ADD_CLASS(SplFixedArray, z_list, sub, allow, ce_flags); \ |
202 | 8 | SPL_ADD_CLASS(SplHeap, z_list, sub, allow, ce_flags); \ |
203 | 8 | SPL_ADD_CLASS(SplMinHeap, z_list, sub, allow, ce_flags); \ |
204 | 8 | SPL_ADD_CLASS(SplMaxHeap, z_list, sub, allow, ce_flags); \ |
205 | 8 | SPL_ADD_CLASS(SplObjectStorage, z_list, sub, allow, ce_flags); \ |
206 | 8 | SPL_ADD_CLASS(SplObserver, z_list, sub, allow, ce_flags); \ |
207 | 8 | SPL_ADD_CLASS(SplPriorityQueue, z_list, sub, allow, ce_flags); \ |
208 | 8 | SPL_ADD_CLASS(SplQueue, z_list, sub, allow, ce_flags); \ |
209 | 8 | SPL_ADD_CLASS(SplStack, z_list, sub, allow, ce_flags); \ |
210 | 8 | SPL_ADD_CLASS(SplSubject, z_list, sub, allow, ce_flags); \ |
211 | 8 | SPL_ADD_CLASS(SplTempFileObject, z_list, sub, allow, ce_flags); \ |
212 | 8 | SPL_ADD_CLASS(UnderflowException, z_list, sub, allow, ce_flags); \ |
213 | 8 | SPL_ADD_CLASS(UnexpectedValueException, z_list, sub, allow, ce_flags); \ |
214 | | |
215 | | /* {{{ Return an array containing the names of all classes and interfaces defined in SPL */ |
216 | | PHP_FUNCTION(spl_classes) |
217 | 0 | { |
218 | 0 | ZEND_PARSE_PARAMETERS_NONE(); |
219 | | |
220 | 0 | array_init(return_value); |
221 | |
|
222 | 0 | SPL_LIST_CLASSES(return_value, 0, 0, 0) |
223 | 0 | } |
224 | | /* }}} */ |
225 | | |
226 | | static bool spl_autoload(zend_string *lc_name, const char *ext, size_t ext_len) /* {{{ */ |
227 | 0 | { |
228 | 0 | zend_string *class_file; |
229 | 0 | zval dummy; |
230 | 0 | zend_file_handle file_handle; |
231 | 0 | zval result; |
232 | |
|
233 | 0 | class_file = zend_string_concat2(ZSTR_VAL(lc_name), ZSTR_LEN(lc_name), ext, ext_len); |
234 | |
|
235 | 0 | #if DEFAULT_SLASH != '\\' |
236 | 0 | { |
237 | 0 | char *ptr = ZSTR_VAL(class_file); |
238 | 0 | const char *end = ptr + ZSTR_LEN(class_file); |
239 | |
|
240 | 0 | while ((ptr = memchr(ptr, '\\', (end - ptr))) != NULL) { |
241 | 0 | *ptr = DEFAULT_SLASH; |
242 | 0 | } |
243 | 0 | } |
244 | 0 | #endif |
245 | |
|
246 | 0 | bool ret = false; |
247 | 0 | zend_stream_init_filename_ex(&file_handle, class_file); |
248 | 0 | if (php_stream_open_for_zend_ex(&file_handle, USE_PATH|STREAM_OPEN_FOR_INCLUDE) == SUCCESS) { |
249 | 0 | zend_string *opened_path; |
250 | 0 | if (!file_handle.opened_path) { |
251 | 0 | file_handle.opened_path = zend_string_copy(class_file); |
252 | 0 | } |
253 | 0 | opened_path = zend_string_copy(file_handle.opened_path); |
254 | 0 | ZVAL_NULL(&dummy); |
255 | 0 | zend_op_array *new_op_array = NULL; |
256 | 0 | if (zend_hash_add(&EG(included_files), opened_path, &dummy)) { |
257 | 0 | new_op_array = zend_compile_file(&file_handle, ZEND_REQUIRE); |
258 | 0 | } |
259 | 0 | zend_string_release_ex(opened_path, false); |
260 | 0 | if (new_op_array) { |
261 | 0 | uint32_t orig_jit_trace_num = EG(jit_trace_num); |
262 | |
|
263 | 0 | ZVAL_UNDEF(&result); |
264 | 0 | zend_execute(new_op_array, &result); |
265 | 0 | EG(jit_trace_num) = orig_jit_trace_num; |
266 | |
|
267 | 0 | destroy_op_array(new_op_array); |
268 | 0 | efree(new_op_array); |
269 | 0 | zval_ptr_dtor(&result); |
270 | |
|
271 | 0 | ret = zend_hash_exists(EG(class_table), lc_name); |
272 | 0 | } |
273 | 0 | } |
274 | 0 | zend_destroy_file_handle(&file_handle); |
275 | 0 | zend_string_release(class_file); |
276 | 0 | return ret; |
277 | 0 | } /* }}} */ |
278 | | |
279 | | /* {{{ Default autoloader implementation */ |
280 | | PHP_FUNCTION(spl_autoload) |
281 | 0 | { |
282 | 0 | size_t pos_len, pos1_len; |
283 | 0 | char *pos, *pos1; |
284 | 0 | zend_string *class_name, *lc_name, *file_exts = NULL; |
285 | |
|
286 | 0 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|S!", &class_name, &file_exts) == FAILURE) { |
287 | 0 | RETURN_THROWS(); |
288 | 0 | } |
289 | | |
290 | 0 | if (!file_exts) { |
291 | 0 | file_exts = spl_autoload_extensions; |
292 | 0 | } |
293 | |
|
294 | 0 | if (file_exts == NULL) { /* autoload_extensions is not initialized, set to defaults */ |
295 | 0 | pos = SPL_DEFAULT_FILE_EXTENSIONS; |
296 | 0 | pos_len = sizeof(SPL_DEFAULT_FILE_EXTENSIONS) - 1; |
297 | 0 | } else { |
298 | 0 | pos = ZSTR_VAL(file_exts); |
299 | 0 | pos_len = ZSTR_LEN(file_exts); |
300 | 0 | } |
301 | |
|
302 | 0 | lc_name = zend_string_tolower(class_name); |
303 | 0 | while (pos && *pos && !EG(exception)) { |
304 | 0 | pos1 = strchr(pos, ','); |
305 | 0 | if (pos1) { |
306 | 0 | pos1_len = (size_t)(pos1 - pos); |
307 | 0 | } else { |
308 | 0 | pos1_len = pos_len; |
309 | 0 | } |
310 | 0 | if (spl_autoload(lc_name, pos, pos1_len)) { |
311 | 0 | break; /* loaded */ |
312 | 0 | } |
313 | 0 | pos = pos1 ? pos1 + 1 : NULL; |
314 | 0 | pos_len = pos1? pos_len - pos1_len - 1 : 0; |
315 | 0 | } |
316 | 0 | zend_string_release(lc_name); |
317 | 0 | } /* }}} */ |
318 | | |
319 | | /* {{{ Register and return default file extensions for spl_autoload */ |
320 | | PHP_FUNCTION(spl_autoload_extensions) |
321 | 0 | { |
322 | 0 | zend_string *file_exts = NULL; |
323 | |
|
324 | 0 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S!", &file_exts) == FAILURE) { |
325 | 0 | RETURN_THROWS(); |
326 | 0 | } |
327 | | |
328 | 0 | if (file_exts) { |
329 | 0 | if (spl_autoload_extensions) { |
330 | 0 | zend_string_release_ex(spl_autoload_extensions, 0); |
331 | 0 | } |
332 | 0 | spl_autoload_extensions = zend_string_copy(file_exts); |
333 | 0 | } |
334 | |
|
335 | 0 | if (spl_autoload_extensions == NULL) { |
336 | 0 | RETURN_STRINGL(SPL_DEFAULT_FILE_EXTENSIONS, sizeof(SPL_DEFAULT_FILE_EXTENSIONS) - 1); |
337 | 0 | } else { |
338 | 0 | zend_string_addref(spl_autoload_extensions); |
339 | 0 | RETURN_STR(spl_autoload_extensions); |
340 | 0 | } |
341 | 0 | } /* }}} */ |
342 | | |
343 | | /* {{{ Try all registered autoload function to load the requested class */ |
344 | | PHP_FUNCTION(spl_autoload_call) |
345 | 0 | { |
346 | 0 | zend_string *class_name; |
347 | |
|
348 | 0 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &class_name) == FAILURE) { |
349 | 0 | RETURN_THROWS(); |
350 | 0 | } |
351 | | |
352 | 0 | zend_string *lc_name = zend_string_tolower(class_name); |
353 | 0 | zend_perform_class_autoload(class_name, lc_name); |
354 | 0 | zend_string_release(lc_name); |
355 | 0 | } /* }}} */ |
356 | | |
357 | | /* {{{ Register given function as autoloader */ |
358 | | PHP_FUNCTION(spl_autoload_register) |
359 | 475 | { |
360 | 475 | bool do_throw = 1; |
361 | 475 | bool prepend = 0; |
362 | 475 | zend_fcall_info fci = {0}; |
363 | 475 | zend_fcall_info_cache fcc; |
364 | | |
365 | 1.42k | ZEND_PARSE_PARAMETERS_START(0, 3) |
366 | 1.42k | Z_PARAM_OPTIONAL |
367 | 1.90k | Z_PARAM_FUNC_OR_NULL(fci, fcc) |
368 | 1.44k | Z_PARAM_BOOL(do_throw) |
369 | 80 | Z_PARAM_BOOL(prepend) |
370 | 475 | ZEND_PARSE_PARAMETERS_END(); |
371 | | |
372 | 472 | if (!do_throw) { |
373 | 0 | php_error_docref(NULL, E_NOTICE, "Argument #2 ($do_throw) has been ignored, " |
374 | 0 | "spl_autoload_register() will always throw"); |
375 | 0 | } |
376 | | |
377 | | /* If first arg is not null */ |
378 | 472 | if (ZEND_FCI_INITIALIZED(fci)) { |
379 | 472 | if (!ZEND_FCC_INITIALIZED(fcc)) { |
380 | | /* Call trampoline has been cleared by zpp. Refetch it, because we want to deal |
381 | | * with it ourselves. It is important that it is not refetched on every call, |
382 | | * because calls may occur from different scopes. */ |
383 | 15 | zend_is_callable_ex(&fci.function_name, NULL, IS_CALLABLE_SUPPRESS_DEPRECATIONS, NULL, &fcc, NULL); |
384 | 15 | } |
385 | | |
386 | 472 | if (fcc.function_handler->type == ZEND_INTERNAL_FUNCTION && |
387 | 0 | fcc.function_handler->internal_function.handler == zif_spl_autoload_call) { |
388 | 0 | zend_argument_value_error(1, "must not be the spl_autoload_call() function"); |
389 | 0 | RETURN_THROWS(); |
390 | 0 | } |
391 | 472 | } else { |
392 | 0 | memset(&fcc, 0, sizeof(fcc)); |
393 | 0 | fcc.function_handler = zend_hash_str_find_ptr(CG(function_table), ZEND_STRL("spl_autoload")); |
394 | 0 | } |
395 | | |
396 | 472 | zend_autoload_register_class_loader(&fcc, prepend); |
397 | | |
398 | 472 | RETURN_TRUE; |
399 | 472 | } /* }}} */ |
400 | | |
401 | | /* {{{ Unregister given function as autoloader */ |
402 | | PHP_FUNCTION(spl_autoload_unregister) |
403 | 0 | { |
404 | 0 | zend_fcall_info fci; |
405 | 0 | zend_fcall_info_cache fcc; |
406 | |
|
407 | 0 | ZEND_PARSE_PARAMETERS_START(1, 1) |
408 | 0 | Z_PARAM_FUNC_NO_TRAMPOLINE_FREE(fci, fcc) |
409 | 0 | ZEND_PARSE_PARAMETERS_END(); |
410 | | |
411 | 0 | if (zend_string_equals_literal(fcc.function_handler->common.function_name, "spl_autoload_call")) { |
412 | | /* Release trampoline */ |
413 | 0 | zend_release_fcall_info_cache(&fcc); |
414 | 0 | php_error_docref(NULL, E_DEPRECATED, |
415 | 0 | "Using spl_autoload_call() as a callback for spl_autoload_unregister() is deprecated," |
416 | 0 | " to remove all registered autoloaders, call spl_autoload_unregister()" |
417 | 0 | " for all values returned from spl_autoload_functions()"); |
418 | 0 | if (UNEXPECTED(EG(exception))) { |
419 | 0 | RETURN_THROWS(); |
420 | 0 | } |
421 | 0 | zend_autoload_clean_class_loaders(); |
422 | 0 | RETURN_TRUE; |
423 | 0 | } |
424 | | |
425 | 0 | RETVAL_BOOL(zend_autoload_unregister_class_loader(&fcc)); |
426 | | /* Release trampoline */ |
427 | 0 | zend_release_fcall_info_cache(&fcc); |
428 | 0 | } /* }}} */ |
429 | | |
430 | | /* {{{ Return all registered autoloader functions */ |
431 | | PHP_FUNCTION(spl_autoload_functions) |
432 | 0 | { |
433 | 0 | ZEND_PARSE_PARAMETERS_NONE(); |
434 | | |
435 | 0 | zend_autoload_fcc_map_to_callable_zval_map(return_value); |
436 | 0 | } /* }}} */ |
437 | | |
438 | | /* {{{ Return hash id for given object */ |
439 | | PHP_FUNCTION(spl_object_hash) |
440 | 418 | { |
441 | 418 | zend_object *obj; |
442 | | |
443 | 1.25k | ZEND_PARSE_PARAMETERS_START(1, 1) |
444 | 1.67k | Z_PARAM_OBJ(obj) |
445 | 418 | ZEND_PARSE_PARAMETERS_END(); |
446 | | |
447 | 418 | RETURN_NEW_STR(php_spl_object_hash(obj)); |
448 | 418 | } |
449 | | /* }}} */ |
450 | | |
451 | | /* {{{ Returns the integer object handle for the given object */ |
452 | | PHP_FUNCTION(spl_object_id) |
453 | 385 | { |
454 | 385 | zend_object *obj; |
455 | | |
456 | 1.15k | ZEND_PARSE_PARAMETERS_START(1, 1) |
457 | 1.54k | Z_PARAM_OBJ(obj) |
458 | 385 | ZEND_PARSE_PARAMETERS_END(); |
459 | | |
460 | 385 | RETURN_LONG((zend_long)obj->handle); |
461 | 385 | } |
462 | | /* }}} */ |
463 | | |
464 | | PHPAPI zend_string *php_spl_object_hash(zend_object *obj) /* {{{*/ |
465 | 418 | { |
466 | 418 | return strpprintf(32, "%016zx0000000000000000", (intptr_t)obj->handle); |
467 | 418 | } |
468 | | /* }}} */ |
469 | | |
470 | | static void spl_build_class_list_string(zval *entry, char **list) /* {{{ */ |
471 | 220 | { |
472 | 220 | char *res; |
473 | | |
474 | 220 | spprintf(&res, 0, "%s, %s", *list, Z_STRVAL_P(entry)); |
475 | 220 | efree(*list); |
476 | 220 | *list = res; |
477 | 220 | } /* }}} */ |
478 | | |
479 | | /* {{{ PHP_MINFO(spl) */ |
480 | | PHP_MINFO_FUNCTION(spl) |
481 | 4 | { |
482 | 4 | zval list, *zv; |
483 | 4 | char *strg; |
484 | | |
485 | 4 | php_info_print_table_start(); |
486 | 4 | php_info_print_table_row(2, "SPL support", "enabled"); |
487 | | |
488 | 4 | array_init(&list); |
489 | 4 | SPL_LIST_CLASSES(&list, 0, 1, ZEND_ACC_INTERFACE) |
490 | 4 | strg = estrdup(""); |
491 | 48 | ZEND_HASH_MAP_FOREACH_VAL(Z_ARRVAL_P(&list), zv) { |
492 | 48 | spl_build_class_list_string(zv, &strg); |
493 | 48 | } ZEND_HASH_FOREACH_END(); |
494 | 4 | zend_array_destroy(Z_ARR(list)); |
495 | 4 | php_info_print_table_row(2, "Interfaces", strg + 2); |
496 | 4 | efree(strg); |
497 | | |
498 | 4 | array_init(&list); |
499 | 4 | SPL_LIST_CLASSES(&list, 0, -1, ZEND_ACC_INTERFACE) |
500 | 4 | strg = estrdup(""); |
501 | 408 | ZEND_HASH_MAP_FOREACH_VAL(Z_ARRVAL_P(&list), zv) { |
502 | 408 | spl_build_class_list_string(zv, &strg); |
503 | 408 | } ZEND_HASH_FOREACH_END(); |
504 | 4 | zend_array_destroy(Z_ARR(list)); |
505 | 4 | php_info_print_table_row(2, "Classes", strg + 2); |
506 | 4 | efree(strg); |
507 | | |
508 | 4 | php_info_print_table_end(); |
509 | 4 | } |
510 | | /* }}} */ |
511 | | |
512 | | /* {{{ PHP_MINIT_FUNCTION(spl) */ |
513 | | PHP_MINIT_FUNCTION(spl) |
514 | 16 | { |
515 | 16 | PHP_MINIT(spl_exceptions)(INIT_FUNC_ARGS_PASSTHRU); |
516 | 16 | PHP_MINIT(spl_iterators)(INIT_FUNC_ARGS_PASSTHRU); |
517 | 16 | PHP_MINIT(spl_array)(INIT_FUNC_ARGS_PASSTHRU); |
518 | 16 | PHP_MINIT(spl_directory)(INIT_FUNC_ARGS_PASSTHRU); |
519 | 16 | PHP_MINIT(spl_dllist)(INIT_FUNC_ARGS_PASSTHRU); |
520 | 16 | PHP_MINIT(spl_heap)(INIT_FUNC_ARGS_PASSTHRU); |
521 | 16 | PHP_MINIT(spl_fixedarray)(INIT_FUNC_ARGS_PASSTHRU); |
522 | 16 | PHP_MINIT(spl_observer)(INIT_FUNC_ARGS_PASSTHRU); |
523 | | |
524 | 16 | return SUCCESS; |
525 | 16 | } |
526 | | /* }}} */ |
527 | | |
528 | | PHP_RINIT_FUNCTION(spl) /* {{{ */ |
529 | 191k | { |
530 | 191k | spl_autoload_extensions = NULL; |
531 | 191k | return SUCCESS; |
532 | 191k | } /* }}} */ |
533 | | |
534 | | PHP_RSHUTDOWN_FUNCTION(spl) /* {{{ */ |
535 | 191k | { |
536 | 191k | if (spl_autoload_extensions) { |
537 | 0 | zend_string_release_ex(spl_autoload_extensions, 0); |
538 | | spl_autoload_extensions = NULL; |
539 | 0 | } |
540 | 191k | return SUCCESS; |
541 | 191k | } /* }}} */ |
542 | | |
543 | | static const zend_module_dep spl_deps[] = { |
544 | | ZEND_MOD_REQUIRED("json") |
545 | | ZEND_MOD_END |
546 | | }; |
547 | | |
548 | | zend_module_entry spl_module_entry = { |
549 | | STANDARD_MODULE_HEADER_EX, NULL, |
550 | | spl_deps, |
551 | | "SPL", |
552 | | ext_functions, |
553 | | PHP_MINIT(spl), |
554 | | NULL, |
555 | | PHP_RINIT(spl), |
556 | | PHP_RSHUTDOWN(spl), |
557 | | PHP_MINFO(spl), |
558 | | PHP_SPL_VERSION, |
559 | | STANDARD_MODULE_PROPERTIES |
560 | | }; |