xref: /PHP-7.2/ext/spl/php_spl.c (revision 7a7ec01a)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1997-2018 The PHP Group                                |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 3.01 of the PHP license,      |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.php.net/license/3_01.txt                                  |
11    | If you did not receive a copy of the PHP license and are unable to   |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@php.net so we can mail you a copy immediately.               |
14    +----------------------------------------------------------------------+
15    | Authors: Marcus Boerger <helly@php.net>                              |
16    +----------------------------------------------------------------------+
17  */
18 
19 /* $Id$ */
20 
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include "php.h"
26 #include "php_ini.h"
27 #include "php_main.h"
28 #include "ext/standard/info.h"
29 #include "php_spl.h"
30 #include "spl_functions.h"
31 #include "spl_engine.h"
32 #include "spl_array.h"
33 #include "spl_directory.h"
34 #include "spl_iterators.h"
35 #include "spl_exceptions.h"
36 #include "spl_observer.h"
37 #include "spl_dllist.h"
38 #include "spl_fixedarray.h"
39 #include "spl_heap.h"
40 #include "zend_exceptions.h"
41 #include "zend_interfaces.h"
42 #include "ext/standard/php_mt_rand.h"
43 #include "main/snprintf.h"
44 
45 #ifdef COMPILE_DL_SPL
46 ZEND_GET_MODULE(spl)
47 #endif
48 
ZEND_DECLARE_MODULE_GLOBALS(spl)49 ZEND_DECLARE_MODULE_GLOBALS(spl)
50 
51 #define SPL_DEFAULT_FILE_EXTENSIONS ".inc,.php"
52 
53 /* {{{ PHP_GINIT_FUNCTION
54  */
55 static PHP_GINIT_FUNCTION(spl)
56 {
57 	spl_globals->autoload_extensions     = NULL;
58 	spl_globals->autoload_functions      = NULL;
59 	spl_globals->autoload_running        = 0;
60 }
61 /* }}} */
62 
spl_find_ce_by_name(zend_string * name,zend_bool autoload)63 static zend_class_entry * spl_find_ce_by_name(zend_string *name, zend_bool autoload)
64 {
65 	zend_class_entry *ce;
66 
67 	if (!autoload) {
68 		zend_string *lc_name = zend_string_alloc(ZSTR_LEN(name), 0);
69 		zend_str_tolower_copy(ZSTR_VAL(lc_name), ZSTR_VAL(name), ZSTR_LEN(name));
70 
71 		ce = zend_hash_find_ptr(EG(class_table), lc_name);
72 		zend_string_free(lc_name);
73 	} else {
74  		ce = zend_lookup_class(name);
75  	}
76  	if (ce == NULL) {
77 		php_error_docref(NULL, E_WARNING, "Class %s does not exist%s", ZSTR_VAL(name), autoload ? " and could not be loaded" : "");
78 		return NULL;
79 	}
80 
81 	return ce;
82 }
83 
84 /* {{{ proto array class_parents(object instance [, boolean autoload = true])
85  Return an array containing the names of all parent classes */
PHP_FUNCTION(class_parents)86 PHP_FUNCTION(class_parents)
87 {
88 	zval *obj;
89 	zend_class_entry *parent_class, *ce;
90 	zend_bool autoload = 1;
91 
92 	if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|b", &obj, &autoload) == FAILURE) {
93 		RETURN_FALSE;
94 	}
95 
96 	if (Z_TYPE_P(obj) != IS_OBJECT && Z_TYPE_P(obj) != IS_STRING) {
97 		php_error_docref(NULL, E_WARNING, "object or string expected");
98 		RETURN_FALSE;
99 	}
100 
101 	if (Z_TYPE_P(obj) == IS_STRING) {
102 		if (NULL == (ce = spl_find_ce_by_name(Z_STR_P(obj), autoload))) {
103 			RETURN_FALSE;
104 		}
105 	} else {
106 		ce = Z_OBJCE_P(obj);
107 	}
108 
109 	array_init(return_value);
110 	parent_class = ce->parent;
111 	while (parent_class) {
112 		spl_add_class_name(return_value, parent_class, 0, 0);
113 		parent_class = parent_class->parent;
114 	}
115 }
116 /* }}} */
117 
118 /* {{{ proto array class_implements(mixed what [, bool autoload ])
119  Return all classes and interfaces implemented by SPL */
PHP_FUNCTION(class_implements)120 PHP_FUNCTION(class_implements)
121 {
122 	zval *obj;
123 	zend_bool autoload = 1;
124 	zend_class_entry *ce;
125 
126 	if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|b", &obj, &autoload) == FAILURE) {
127 		RETURN_FALSE;
128 	}
129 	if (Z_TYPE_P(obj) != IS_OBJECT && Z_TYPE_P(obj) != IS_STRING) {
130 		php_error_docref(NULL, E_WARNING, "object or string expected");
131 		RETURN_FALSE;
132 	}
133 
134 	if (Z_TYPE_P(obj) == IS_STRING) {
135 		if (NULL == (ce = spl_find_ce_by_name(Z_STR_P(obj), autoload))) {
136 			RETURN_FALSE;
137 		}
138 	} else {
139 		ce = Z_OBJCE_P(obj);
140 	}
141 
142 	array_init(return_value);
143 	spl_add_interfaces(return_value, ce, 1, ZEND_ACC_INTERFACE);
144 }
145 /* }}} */
146 
147 /* {{{ proto array class_uses(mixed what [, bool autoload ])
148  Return all traits used by a class. */
PHP_FUNCTION(class_uses)149 PHP_FUNCTION(class_uses)
150 {
151 	zval *obj;
152 	zend_bool autoload = 1;
153 	zend_class_entry *ce;
154 
155 	if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|b", &obj, &autoload) == FAILURE) {
156 		RETURN_FALSE;
157 	}
158 	if (Z_TYPE_P(obj) != IS_OBJECT && Z_TYPE_P(obj) != IS_STRING) {
159 		php_error_docref(NULL, E_WARNING, "object or string expected");
160 		RETURN_FALSE;
161 	}
162 
163 	if (Z_TYPE_P(obj) == IS_STRING) {
164 		if (NULL == (ce = spl_find_ce_by_name(Z_STR_P(obj), autoload))) {
165 			RETURN_FALSE;
166 		}
167 	} else {
168 		ce = Z_OBJCE_P(obj);
169 	}
170 
171 	array_init(return_value);
172 	spl_add_traits(return_value, ce, 1, ZEND_ACC_TRAIT);
173 }
174 /* }}} */
175 
176 #define SPL_ADD_CLASS(class_name, z_list, sub, allow, ce_flags) \
177 	spl_add_classes(spl_ce_ ## class_name, z_list, sub, allow, ce_flags)
178 
179 #define SPL_LIST_CLASSES(z_list, sub, allow, ce_flags) \
180 	SPL_ADD_CLASS(AppendIterator, z_list, sub, allow, ce_flags); \
181 	SPL_ADD_CLASS(ArrayIterator, z_list, sub, allow, ce_flags); \
182 	SPL_ADD_CLASS(ArrayObject, z_list, sub, allow, ce_flags); \
183 	SPL_ADD_CLASS(BadFunctionCallException, z_list, sub, allow, ce_flags); \
184 	SPL_ADD_CLASS(BadMethodCallException, z_list, sub, allow, ce_flags); \
185 	SPL_ADD_CLASS(CachingIterator, z_list, sub, allow, ce_flags); \
186 	SPL_ADD_CLASS(CallbackFilterIterator, z_list, sub, allow, ce_flags); \
187 	SPL_ADD_CLASS(DirectoryIterator, z_list, sub, allow, ce_flags); \
188 	SPL_ADD_CLASS(DomainException, z_list, sub, allow, ce_flags); \
189 	SPL_ADD_CLASS(EmptyIterator, z_list, sub, allow, ce_flags); \
190 	SPL_ADD_CLASS(FilesystemIterator, z_list, sub, allow, ce_flags); \
191 	SPL_ADD_CLASS(FilterIterator, z_list, sub, allow, ce_flags); \
192 	SPL_ADD_CLASS(GlobIterator, z_list, sub, allow, ce_flags); \
193 	SPL_ADD_CLASS(InfiniteIterator, z_list, sub, allow, ce_flags); \
194 	SPL_ADD_CLASS(InvalidArgumentException, z_list, sub, allow, ce_flags); \
195 	SPL_ADD_CLASS(IteratorIterator, z_list, sub, allow, ce_flags); \
196 	SPL_ADD_CLASS(LengthException, z_list, sub, allow, ce_flags); \
197 	SPL_ADD_CLASS(LimitIterator, z_list, sub, allow, ce_flags); \
198 	SPL_ADD_CLASS(LogicException, z_list, sub, allow, ce_flags); \
199 	SPL_ADD_CLASS(MultipleIterator, z_list, sub, allow, ce_flags); \
200 	SPL_ADD_CLASS(NoRewindIterator, z_list, sub, allow, ce_flags); \
201 	SPL_ADD_CLASS(OuterIterator, z_list, sub, allow, ce_flags); \
202 	SPL_ADD_CLASS(OutOfBoundsException, z_list, sub, allow, ce_flags); \
203 	SPL_ADD_CLASS(OutOfRangeException, z_list, sub, allow, ce_flags); \
204 	SPL_ADD_CLASS(OverflowException, z_list, sub, allow, ce_flags); \
205 	SPL_ADD_CLASS(ParentIterator, z_list, sub, allow, ce_flags); \
206 	SPL_ADD_CLASS(RangeException, z_list, sub, allow, ce_flags); \
207 	SPL_ADD_CLASS(RecursiveArrayIterator, z_list, sub, allow, ce_flags); \
208 	SPL_ADD_CLASS(RecursiveCachingIterator, z_list, sub, allow, ce_flags); \
209 	SPL_ADD_CLASS(RecursiveCallbackFilterIterator, z_list, sub, allow, ce_flags); \
210 	SPL_ADD_CLASS(RecursiveDirectoryIterator, z_list, sub, allow, ce_flags); \
211 	SPL_ADD_CLASS(RecursiveFilterIterator, z_list, sub, allow, ce_flags); \
212 	SPL_ADD_CLASS(RecursiveIterator, z_list, sub, allow, ce_flags); \
213 	SPL_ADD_CLASS(RecursiveIteratorIterator, z_list, sub, allow, ce_flags); \
214 	SPL_ADD_CLASS(RecursiveRegexIterator, z_list, sub, allow, ce_flags); \
215 	SPL_ADD_CLASS(RecursiveTreeIterator, z_list, sub, allow, ce_flags); \
216 	SPL_ADD_CLASS(RegexIterator, z_list, sub, allow, ce_flags); \
217 	SPL_ADD_CLASS(RuntimeException, z_list, sub, allow, ce_flags); \
218 	SPL_ADD_CLASS(SeekableIterator, z_list, sub, allow, ce_flags); \
219 	SPL_ADD_CLASS(SplDoublyLinkedList, z_list, sub, allow, ce_flags); \
220 	SPL_ADD_CLASS(SplFileInfo, z_list, sub, allow, ce_flags); \
221 	SPL_ADD_CLASS(SplFileObject, z_list, sub, allow, ce_flags); \
222 	SPL_ADD_CLASS(SplFixedArray, z_list, sub, allow, ce_flags); \
223 	SPL_ADD_CLASS(SplHeap, z_list, sub, allow, ce_flags); \
224 	SPL_ADD_CLASS(SplMinHeap, z_list, sub, allow, ce_flags); \
225 	SPL_ADD_CLASS(SplMaxHeap, z_list, sub, allow, ce_flags); \
226 	SPL_ADD_CLASS(SplObjectStorage, z_list, sub, allow, ce_flags); \
227 	SPL_ADD_CLASS(SplObserver, z_list, sub, allow, ce_flags); \
228 	SPL_ADD_CLASS(SplPriorityQueue, z_list, sub, allow, ce_flags); \
229 	SPL_ADD_CLASS(SplQueue, z_list, sub, allow, ce_flags); \
230 	SPL_ADD_CLASS(SplStack, z_list, sub, allow, ce_flags); \
231 	SPL_ADD_CLASS(SplSubject, z_list, sub, allow, ce_flags); \
232 	SPL_ADD_CLASS(SplTempFileObject, z_list, sub, allow, ce_flags); \
233 	SPL_ADD_CLASS(UnderflowException, z_list, sub, allow, ce_flags); \
234 	SPL_ADD_CLASS(UnexpectedValueException, z_list, sub, allow, ce_flags); \
235 
236 /* {{{ proto array spl_classes()
237  Return an array containing the names of all clsses and interfaces defined in SPL */
PHP_FUNCTION(spl_classes)238 PHP_FUNCTION(spl_classes)
239 {
240 	array_init(return_value);
241 
242 	SPL_LIST_CLASSES(return_value, 0, 0, 0)
243 }
244 /* }}} */
245 
spl_autoload(zend_string * class_name,zend_string * lc_name,const char * ext,int ext_len)246 static int spl_autoload(zend_string *class_name, zend_string *lc_name, const char *ext, int ext_len) /* {{{ */
247 {
248 	char *class_file;
249 	int class_file_len;
250 	zval dummy;
251 	zend_file_handle file_handle;
252 	zend_op_array *new_op_array;
253 	zval result;
254 	int ret;
255 
256 	class_file_len = (int)spprintf(&class_file, 0, "%s%.*s", ZSTR_VAL(lc_name), ext_len, ext);
257 
258 #if DEFAULT_SLASH != '\\'
259 	{
260 		char *ptr = class_file;
261 		char *end = ptr + class_file_len;
262 
263 		while ((ptr = memchr(ptr, '\\', (end - ptr))) != NULL) {
264 			*ptr = DEFAULT_SLASH;
265 		}
266 	}
267 #endif
268 
269 	ret = php_stream_open_for_zend_ex(class_file, &file_handle, USE_PATH|STREAM_OPEN_FOR_INCLUDE);
270 
271 	if (ret == SUCCESS) {
272 		zend_string *opened_path;
273 		if (!file_handle.opened_path) {
274 			file_handle.opened_path = zend_string_init(class_file, class_file_len, 0);
275 		}
276 		opened_path = zend_string_copy(file_handle.opened_path);
277 		ZVAL_NULL(&dummy);
278 		if (zend_hash_add(&EG(included_files), opened_path, &dummy)) {
279 			new_op_array = zend_compile_file(&file_handle, ZEND_REQUIRE);
280 			zend_destroy_file_handle(&file_handle);
281 		} else {
282 			new_op_array = NULL;
283 			zend_file_handle_dtor(&file_handle);
284 		}
285 		zend_string_release(opened_path);
286 		if (new_op_array) {
287 			ZVAL_UNDEF(&result);
288 			zend_execute(new_op_array, &result);
289 
290 			destroy_op_array(new_op_array);
291 			efree(new_op_array);
292 			if (!EG(exception)) {
293 				zval_ptr_dtor(&result);
294 			}
295 
296 			efree(class_file);
297 			return zend_hash_exists(EG(class_table), lc_name);
298 		}
299 	}
300 	efree(class_file);
301 	return 0;
302 } /* }}} */
303 
304 /* {{{ proto void spl_autoload(string class_name [, string file_extensions])
305  Default implementation for __autoload() */
PHP_FUNCTION(spl_autoload)306 PHP_FUNCTION(spl_autoload)
307 {
308 	int pos_len, pos1_len;
309 	char *pos, *pos1;
310 	zend_string *class_name, *lc_name, *file_exts = SPL_G(autoload_extensions);
311 
312 	if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|S", &class_name, &file_exts) == FAILURE) {
313 		RETURN_FALSE;
314 	}
315 
316 	if (file_exts == NULL) { /* autoload_extensions is not initialized, set to defaults */
317 		pos = SPL_DEFAULT_FILE_EXTENSIONS;
318 		pos_len = sizeof(SPL_DEFAULT_FILE_EXTENSIONS) - 1;
319 	} else {
320 		pos = ZSTR_VAL(file_exts);
321 		pos_len = (int)ZSTR_LEN(file_exts);
322 	}
323 
324 	lc_name = zend_string_alloc(ZSTR_LEN(class_name), 0);
325 	zend_str_tolower_copy(ZSTR_VAL(lc_name), ZSTR_VAL(class_name), ZSTR_LEN(class_name));
326 	while (pos && *pos && !EG(exception)) {
327 		pos1 = strchr(pos, ',');
328 		if (pos1) {
329 			pos1_len = (int)(pos1 - pos);
330 		} else {
331 			pos1_len = pos_len;
332 		}
333 		if (spl_autoload(class_name, lc_name, pos, pos1_len)) {
334 			break; /* loaded */
335 		}
336 		pos = pos1 ? pos1 + 1 : NULL;
337 		pos_len = pos1? pos_len - pos1_len - 1 : 0;
338 	}
339 	zend_string_free(lc_name);
340 } /* }}} */
341 
342 /* {{{ proto string spl_autoload_extensions([string file_extensions])
343  Register and return default file extensions for spl_autoload */
PHP_FUNCTION(spl_autoload_extensions)344 PHP_FUNCTION(spl_autoload_extensions)
345 {
346 	zend_string *file_exts = NULL;
347 
348 	if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S", &file_exts) == FAILURE) {
349 		return;
350 	}
351 	if (file_exts) {
352 		if (SPL_G(autoload_extensions)) {
353 			zend_string_release(SPL_G(autoload_extensions));
354 		}
355 		SPL_G(autoload_extensions) = zend_string_copy(file_exts);
356 	}
357 
358 	if (SPL_G(autoload_extensions) == NULL) {
359 		RETURN_STRINGL(SPL_DEFAULT_FILE_EXTENSIONS, sizeof(SPL_DEFAULT_FILE_EXTENSIONS) - 1);
360 	} else {
361 		zend_string_addref(SPL_G(autoload_extensions));
362 		RETURN_STR(SPL_G(autoload_extensions));
363 	}
364 } /* }}} */
365 
366 typedef struct {
367 	zend_function *func_ptr;
368 	zval obj;
369 	zval closure;
370 	zend_class_entry *ce;
371 } autoload_func_info;
372 
autoload_func_info_dtor(zval * element)373 static void autoload_func_info_dtor(zval *element)
374 {
375 	autoload_func_info *alfi = (autoload_func_info*)Z_PTR_P(element);
376 	if (!Z_ISUNDEF(alfi->obj)) {
377 		zval_ptr_dtor(&alfi->obj);
378 	}
379 	if (alfi->func_ptr &&
380 		UNEXPECTED(alfi->func_ptr->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
381 		zend_string_release(alfi->func_ptr->common.function_name);
382 		zend_free_trampoline(alfi->func_ptr);
383 	}
384 	if (!Z_ISUNDEF(alfi->closure)) {
385 		zval_ptr_dtor(&alfi->closure);
386 	}
387 	efree(alfi);
388 }
389 
390 /* {{{ proto void spl_autoload_call(string class_name)
391  Try all registerd autoload function to load the requested class */
PHP_FUNCTION(spl_autoload_call)392 PHP_FUNCTION(spl_autoload_call)
393 {
394 	zval *class_name, retval;
395 	zend_string *lc_name, *func_name;
396 	autoload_func_info *alfi;
397 
398 	if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &class_name) == FAILURE || Z_TYPE_P(class_name) != IS_STRING) {
399 		return;
400 	}
401 
402 	if (SPL_G(autoload_functions)) {
403 		HashPosition pos;
404 		zend_ulong num_idx;
405 		zend_function *func;
406 		zend_fcall_info fci;
407 		zend_fcall_info_cache fcic;
408 		zend_class_entry *called_scope = zend_get_called_scope(execute_data);
409 		int l_autoload_running = SPL_G(autoload_running);
410 
411 		SPL_G(autoload_running) = 1;
412 		lc_name = zend_string_tolower(Z_STR_P(class_name));
413 
414 		fci.size = sizeof(fci);
415 		fci.retval = &retval;
416 		fci.param_count = 1;
417 		fci.params = class_name;
418 		fci.no_separation = 1;
419 
420 		ZVAL_UNDEF(&fci.function_name); /* Unused */
421 		fcic.initialized = 1;
422 
423 		zend_hash_internal_pointer_reset_ex(SPL_G(autoload_functions), &pos);
424 		while (zend_hash_get_current_key_ex(SPL_G(autoload_functions), &func_name, &num_idx, &pos) == HASH_KEY_IS_STRING) {
425 			alfi = zend_hash_get_current_data_ptr_ex(SPL_G(autoload_functions), &pos);
426 			func = alfi->func_ptr;
427 			if (UNEXPECTED(func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
428 				func = emalloc(sizeof(zend_op_array));
429 				memcpy(func, alfi->func_ptr, sizeof(zend_op_array));
430 				zend_string_addref(func->op_array.function_name);
431 			}
432 			ZVAL_UNDEF(&retval);
433 			fcic.function_handler = func;
434 			if (Z_ISUNDEF(alfi->obj)) {
435 				fci.object = NULL;
436 				fcic.object = NULL;
437 				fcic.calling_scope = alfi->ce;
438 				if (alfi->ce &&
439 				    (!called_scope ||
440 				     !instanceof_function(called_scope, alfi->ce))) {
441 					fcic.called_scope = alfi->ce;
442 				} else {
443 					fcic.called_scope = called_scope;
444 				}
445 			} else {
446 				fci.object = Z_OBJ(alfi->obj);
447 				fcic.object = Z_OBJ(alfi->obj);
448 				fcic.called_scope = Z_OBJCE(alfi->obj);
449 			}
450 
451 			zend_call_function(&fci, &fcic);
452 
453 			zend_exception_save();
454 			zval_ptr_dtor(&retval);
455 			if (pos + 1 == SPL_G(autoload_functions)->nNumUsed ||
456 			    zend_hash_exists(EG(class_table), lc_name)) {
457 				break;
458 			}
459 			zend_hash_move_forward_ex(SPL_G(autoload_functions), &pos);
460 		}
461 		zend_exception_restore();
462 		zend_string_release(lc_name);
463 		SPL_G(autoload_running) = l_autoload_running;
464 	} else {
465 		/* do not use or overwrite &EG(autoload_func) here */
466 		zend_call_method_with_1_params(NULL, NULL, NULL, "spl_autoload", NULL, class_name);
467 	}
468 } /* }}} */
469 
470 #define HT_MOVE_TAIL_TO_HEAD(ht)						        \
471 	do {												        \
472 		Bucket tmp = (ht)->arData[(ht)->nNumUsed-1];				\
473 		memmove((ht)->arData + 1, (ht)->arData,					\
474 			sizeof(Bucket) * ((ht)->nNumUsed - 1));				\
475 		(ht)->arData[0] = tmp;									\
476 		zend_hash_rehash(ht);						        	\
477 	} while (0)
478 
479 /* {{{ proto bool spl_autoload_register([mixed autoload_function [, bool throw [, bool prepend]]])
480  Register given function as __autoload() implementation */
PHP_FUNCTION(spl_autoload_register)481 PHP_FUNCTION(spl_autoload_register)
482 {
483 	zend_string *func_name;
484 	char *error = NULL;
485 	zend_string *lc_name;
486 	zval *zcallable = NULL;
487 	zend_bool do_throw = 1;
488 	zend_bool prepend  = 0;
489 	zend_function *spl_func_ptr;
490 	autoload_func_info alfi;
491 	zend_object *obj_ptr;
492 	zend_fcall_info_cache fcc;
493 
494 	if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "|zbb", &zcallable, &do_throw, &prepend) == FAILURE) {
495 		return;
496 	}
497 
498 	if (ZEND_NUM_ARGS()) {
499 		if (!zend_is_callable_ex(zcallable, NULL, IS_CALLABLE_STRICT, &func_name, &fcc, &error)) {
500 			alfi.ce = fcc.calling_scope;
501 			alfi.func_ptr = fcc.function_handler;
502 			obj_ptr = fcc.object;
503 			if (Z_TYPE_P(zcallable) == IS_ARRAY) {
504 				if (!obj_ptr && alfi.func_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) {
505 					if (do_throw) {
506 						zend_throw_exception_ex(spl_ce_LogicException, 0, "Passed array specifies a non static method but no object (%s)", error);
507 					}
508 					if (error) {
509 						efree(error);
510 					}
511 					zend_string_release(func_name);
512 					RETURN_FALSE;
513 				} else if (do_throw) {
514 					zend_throw_exception_ex(spl_ce_LogicException, 0, "Passed array does not specify %s %smethod (%s)", alfi.func_ptr ? "a callable" : "an existing", !obj_ptr ? "static " : "", error);
515 				}
516 				if (error) {
517 					efree(error);
518 				}
519 				zend_string_release(func_name);
520 				RETURN_FALSE;
521 			} else if (Z_TYPE_P(zcallable) == IS_STRING) {
522 				if (do_throw) {
523 					zend_throw_exception_ex(spl_ce_LogicException, 0, "Function '%s' not %s (%s)", ZSTR_VAL(func_name), alfi.func_ptr ? "callable" : "found", error);
524 				}
525 				if (error) {
526 					efree(error);
527 				}
528 				zend_string_release(func_name);
529 				RETURN_FALSE;
530 			} else {
531 				if (do_throw) {
532 					zend_throw_exception_ex(spl_ce_LogicException, 0, "Illegal value passed (%s)", error);
533 				}
534 				if (error) {
535 					efree(error);
536 				}
537 				zend_string_release(func_name);
538 				RETURN_FALSE;
539 			}
540 		} else if (fcc.function_handler->type == ZEND_INTERNAL_FUNCTION &&
541 				   fcc.function_handler->internal_function.handler == zif_spl_autoload_call) {
542 			if (do_throw) {
543 				zend_throw_exception_ex(spl_ce_LogicException, 0, "Function spl_autoload_call() cannot be registered");
544 			}
545 			if (error) {
546 				efree(error);
547 			}
548 			zend_string_release(func_name);
549 			RETURN_FALSE;
550 		}
551 		alfi.ce = fcc.calling_scope;
552 		alfi.func_ptr = fcc.function_handler;
553 		obj_ptr = fcc.object;
554 		if (error) {
555 			efree(error);
556 		}
557 
558 		if (Z_TYPE_P(zcallable) == IS_OBJECT) {
559 			ZVAL_COPY(&alfi.closure, zcallable);
560 
561 			lc_name = zend_string_alloc(ZSTR_LEN(func_name) + sizeof(uint32_t), 0);
562 			zend_str_tolower_copy(ZSTR_VAL(lc_name), ZSTR_VAL(func_name), ZSTR_LEN(func_name));
563 			memcpy(ZSTR_VAL(lc_name) + ZSTR_LEN(func_name), &Z_OBJ_HANDLE_P(zcallable), sizeof(uint32_t));
564 			ZSTR_VAL(lc_name)[ZSTR_LEN(lc_name)] = '\0';
565 		} else {
566 			ZVAL_UNDEF(&alfi.closure);
567 			/* Skip leading \ */
568 			if (ZSTR_VAL(func_name)[0] == '\\') {
569 				lc_name = zend_string_alloc(ZSTR_LEN(func_name) - 1, 0);
570 				zend_str_tolower_copy(ZSTR_VAL(lc_name), ZSTR_VAL(func_name) + 1, ZSTR_LEN(func_name) - 1);
571 			} else {
572 				lc_name = zend_string_alloc(ZSTR_LEN(func_name), 0);
573 				zend_str_tolower_copy(ZSTR_VAL(lc_name), ZSTR_VAL(func_name), ZSTR_LEN(func_name));
574 			}
575 		}
576 		zend_string_release(func_name);
577 
578 		if (SPL_G(autoload_functions) && zend_hash_exists(SPL_G(autoload_functions), lc_name)) {
579 			if (!Z_ISUNDEF(alfi.closure)) {
580 				Z_DELREF_P(&alfi.closure);
581 			}
582 			goto skip;
583 		}
584 
585 		if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) {
586 			/* add object id to the hash to ensure uniqueness, for more reference look at bug #40091 */
587 			lc_name = zend_string_extend(lc_name, ZSTR_LEN(lc_name) + sizeof(uint32_t), 0);
588 			memcpy(ZSTR_VAL(lc_name) + ZSTR_LEN(lc_name) - sizeof(uint32_t), &obj_ptr->handle, sizeof(uint32_t));
589 			ZSTR_VAL(lc_name)[ZSTR_LEN(lc_name)] = '\0';
590 			ZVAL_OBJ(&alfi.obj, obj_ptr);
591 			Z_ADDREF(alfi.obj);
592 		} else {
593 			ZVAL_UNDEF(&alfi.obj);
594 		}
595 
596 		if (!SPL_G(autoload_functions)) {
597 			ALLOC_HASHTABLE(SPL_G(autoload_functions));
598 			zend_hash_init(SPL_G(autoload_functions), 1, NULL, autoload_func_info_dtor, 0);
599 		}
600 
601 		spl_func_ptr = zend_hash_str_find_ptr(EG(function_table), "spl_autoload", sizeof("spl_autoload") - 1);
602 
603 		if (EG(autoload_func) == spl_func_ptr) { /* registered already, so we insert that first */
604 			autoload_func_info spl_alfi;
605 
606 			spl_alfi.func_ptr = spl_func_ptr;
607 			ZVAL_UNDEF(&spl_alfi.obj);
608 			ZVAL_UNDEF(&spl_alfi.closure);
609 			spl_alfi.ce = NULL;
610 			zend_hash_str_add_mem(SPL_G(autoload_functions), "spl_autoload", sizeof("spl_autoload") - 1,
611 					&spl_alfi, sizeof(autoload_func_info));
612 			if (prepend && SPL_G(autoload_functions)->nNumOfElements > 1) {
613 				/* Move the newly created element to the head of the hashtable */
614 				HT_MOVE_TAIL_TO_HEAD(SPL_G(autoload_functions));
615 			}
616 		}
617 
618 		if (UNEXPECTED(alfi.func_ptr == &EG(trampoline))) {
619 			zend_function *copy = emalloc(sizeof(zend_op_array));
620 
621 			memcpy(copy, alfi.func_ptr, sizeof(zend_op_array));
622 			alfi.func_ptr->common.function_name = NULL;
623 			alfi.func_ptr = copy;
624 		}
625 		if (zend_hash_add_mem(SPL_G(autoload_functions), lc_name, &alfi, sizeof(autoload_func_info)) == NULL) {
626 			if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) {
627 				Z_DELREF(alfi.obj);
628 			}
629 			if (!Z_ISUNDEF(alfi.closure)) {
630 				Z_DELREF(alfi.closure);
631 			}
632 			if (UNEXPECTED(alfi.func_ptr->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
633 				zend_string_release(alfi.func_ptr->common.function_name);
634 				zend_free_trampoline(alfi.func_ptr);
635 			}
636 		}
637 		if (prepend && SPL_G(autoload_functions)->nNumOfElements > 1) {
638 			/* Move the newly created element to the head of the hashtable */
639 			HT_MOVE_TAIL_TO_HEAD(SPL_G(autoload_functions));
640 		}
641 skip:
642 		zend_string_release(lc_name);
643 	}
644 
645 	if (SPL_G(autoload_functions)) {
646 		EG(autoload_func) = zend_hash_str_find_ptr(EG(function_table), "spl_autoload_call", sizeof("spl_autoload_call") - 1);
647 	} else {
648 		EG(autoload_func) =	zend_hash_str_find_ptr(EG(function_table), "spl_autoload", sizeof("spl_autoload") - 1);
649 	}
650 
651 	RETURN_TRUE;
652 } /* }}} */
653 
654 /* {{{ proto bool spl_autoload_unregister(mixed autoload_function)
655  Unregister given function as __autoload() implementation */
PHP_FUNCTION(spl_autoload_unregister)656 PHP_FUNCTION(spl_autoload_unregister)
657 {
658 	zend_string *func_name = NULL;
659 	char *error = NULL;
660 	zend_string *lc_name;
661 	zval *zcallable;
662 	int success = FAILURE;
663 	zend_function *spl_func_ptr;
664 	zend_object *obj_ptr;
665 	zend_fcall_info_cache fcc;
666 
667 	if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zcallable) == FAILURE) {
668 		return;
669 	}
670 
671 	if (!zend_is_callable_ex(zcallable, NULL, IS_CALLABLE_CHECK_SYNTAX_ONLY, &func_name, &fcc, &error)) {
672 		zend_throw_exception_ex(spl_ce_LogicException, 0, "Unable to unregister invalid function (%s)", error);
673 		if (error) {
674 			efree(error);
675 		}
676 		if (func_name) {
677 			zend_string_release(func_name);
678 		}
679 		RETURN_FALSE;
680 	}
681 	obj_ptr = fcc.object;
682 	if (error) {
683 		efree(error);
684 	}
685 
686 	if (Z_TYPE_P(zcallable) == IS_OBJECT) {
687 		lc_name = zend_string_alloc(ZSTR_LEN(func_name) + sizeof(uint32_t), 0);
688 		zend_str_tolower_copy(ZSTR_VAL(lc_name), ZSTR_VAL(func_name), ZSTR_LEN(func_name));
689 		memcpy(ZSTR_VAL(lc_name) + ZSTR_LEN(func_name), &Z_OBJ_HANDLE_P(zcallable), sizeof(uint32_t));
690 		ZSTR_VAL(lc_name)[ZSTR_LEN(lc_name)] = '\0';
691 	} else {
692 		/* Skip leading \ */
693 		if (ZSTR_VAL(func_name)[0] == '\\') {
694 			lc_name = zend_string_alloc(ZSTR_LEN(func_name) - 1, 0);
695 			zend_str_tolower_copy(ZSTR_VAL(lc_name), ZSTR_VAL(func_name) + 1, ZSTR_LEN(func_name) - 1);
696 		} else {
697 			lc_name = zend_string_alloc(ZSTR_LEN(func_name), 0);
698 			zend_str_tolower_copy(ZSTR_VAL(lc_name), ZSTR_VAL(func_name), ZSTR_LEN(func_name));
699 		}
700 	}
701 	zend_string_release(func_name);
702 
703 	if (SPL_G(autoload_functions)) {
704 		if (ZSTR_LEN(lc_name) == sizeof("spl_autoload_call") - 1 && !strcmp(ZSTR_VAL(lc_name), "spl_autoload_call")) {
705 			/* remove all */
706 			if (!SPL_G(autoload_running)) {
707 				zend_hash_destroy(SPL_G(autoload_functions));
708 				FREE_HASHTABLE(SPL_G(autoload_functions));
709 				SPL_G(autoload_functions) = NULL;
710 				EG(autoload_func) = NULL;
711 			} else {
712 				zend_hash_clean(SPL_G(autoload_functions));
713 			}
714 			success = SUCCESS;
715 		} else {
716 			/* remove specific */
717 			success = zend_hash_del(SPL_G(autoload_functions), lc_name);
718 			if (success != SUCCESS && obj_ptr) {
719 				lc_name = zend_string_extend(lc_name, ZSTR_LEN(lc_name) + sizeof(uint32_t), 0);
720 				memcpy(ZSTR_VAL(lc_name) + ZSTR_LEN(lc_name) - sizeof(uint32_t), &obj_ptr->handle, sizeof(uint32_t));
721 				ZSTR_VAL(lc_name)[ZSTR_LEN(lc_name)] = '\0';
722 				success = zend_hash_del(SPL_G(autoload_functions), lc_name);
723 			}
724 		}
725 	} else if (ZSTR_LEN(lc_name) == sizeof("spl_autoload")-1 && !strcmp(ZSTR_VAL(lc_name), "spl_autoload")) {
726 		/* register single spl_autoload() */
727 		spl_func_ptr = zend_hash_str_find_ptr(EG(function_table), "spl_autoload", sizeof("spl_autoload") - 1);
728 
729 		if (EG(autoload_func) == spl_func_ptr) {
730 			success = SUCCESS;
731 			EG(autoload_func) = NULL;
732 		}
733 	}
734 
735 	zend_string_release(lc_name);
736 	RETURN_BOOL(success == SUCCESS);
737 } /* }}} */
738 
739 /* {{{ proto false|array spl_autoload_functions()
740  Return all registered __autoload() functionns */
PHP_FUNCTION(spl_autoload_functions)741 PHP_FUNCTION(spl_autoload_functions)
742 {
743 	zend_function *fptr;
744 	autoload_func_info *alfi;
745 
746 	if (zend_parse_parameters_none() == FAILURE) {
747 		return;
748 	}
749 
750 	if (!EG(autoload_func)) {
751 		if ((fptr = zend_hash_str_find_ptr(EG(function_table), ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME) - 1))) {
752 			array_init(return_value);
753 			add_next_index_stringl(return_value, ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME)-1);
754 			return;
755 		}
756 		RETURN_FALSE;
757 	}
758 
759 	fptr = zend_hash_str_find_ptr(EG(function_table), "spl_autoload_call", sizeof("spl_autoload_call") - 1);
760 
761 	if (EG(autoload_func) == fptr) {
762 		zend_string *key;
763 		array_init(return_value);
764 		ZEND_HASH_FOREACH_STR_KEY_PTR(SPL_G(autoload_functions), key, alfi) {
765 			if (!Z_ISUNDEF(alfi->closure)) {
766 				Z_ADDREF(alfi->closure);
767 				add_next_index_zval(return_value, &alfi->closure);
768 			} else if (alfi->func_ptr->common.scope) {
769 				zval tmp;
770 
771 				array_init(&tmp);
772 				if (!Z_ISUNDEF(alfi->obj)) {
773 					Z_ADDREF(alfi->obj);
774 					add_next_index_zval(&tmp, &alfi->obj);
775 				} else {
776 					add_next_index_str(&tmp, zend_string_copy(alfi->ce->name));
777 				}
778 				add_next_index_str(&tmp, zend_string_copy(alfi->func_ptr->common.function_name));
779 				add_next_index_zval(return_value, &tmp);
780 			} else {
781 				if (strncmp(ZSTR_VAL(alfi->func_ptr->common.function_name), "__lambda_func", sizeof("__lambda_func") - 1)) {
782 					add_next_index_str(return_value, zend_string_copy(alfi->func_ptr->common.function_name));
783 				} else {
784 					add_next_index_str(return_value, zend_string_copy(key));
785 				}
786 			}
787 		} ZEND_HASH_FOREACH_END();
788 		return;
789 	}
790 
791 	array_init(return_value);
792 	add_next_index_str(return_value, zend_string_copy(EG(autoload_func)->common.function_name));
793 } /* }}} */
794 
795 /* {{{ proto string spl_object_hash(object obj)
796  Return hash id for given object */
PHP_FUNCTION(spl_object_hash)797 PHP_FUNCTION(spl_object_hash)
798 {
799 	zval *obj;
800 
801 	if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &obj) == FAILURE) {
802 		return;
803 	}
804 
805 	RETURN_NEW_STR(php_spl_object_hash(obj));
806 }
807 /* }}} */
808 
809 /* {{{ proto int spl_object_id(object obj)
810  Returns the integer object handle for the given object */
PHP_FUNCTION(spl_object_id)811 PHP_FUNCTION(spl_object_id)
812 {
813 	zval *obj;
814 
815 	ZEND_PARSE_PARAMETERS_START(1, 1)
816 		Z_PARAM_OBJECT(obj)
817 	ZEND_PARSE_PARAMETERS_END();
818 
819 	RETURN_LONG((zend_long)Z_OBJ_HANDLE_P(obj));
820 }
821 /* }}} */
822 
php_spl_object_hash(zval * obj)823 PHPAPI zend_string *php_spl_object_hash(zval *obj) /* {{{*/
824 {
825 	intptr_t hash_handle, hash_handlers;
826 
827 	if (!SPL_G(hash_mask_init)) {
828 		SPL_G(hash_mask_handle)   = (intptr_t)(php_mt_rand() >> 1);
829 		SPL_G(hash_mask_handlers) = (intptr_t)(php_mt_rand() >> 1);
830 		SPL_G(hash_mask_init) = 1;
831 	}
832 
833 	hash_handle   = SPL_G(hash_mask_handle)^(intptr_t)Z_OBJ_HANDLE_P(obj);
834 	hash_handlers = SPL_G(hash_mask_handlers);
835 
836 	return strpprintf(32, "%016zx%016zx", hash_handle, hash_handlers);
837 }
838 /* }}} */
839 
spl_build_class_list_string(zval * entry,char ** list)840 int spl_build_class_list_string(zval *entry, char **list) /* {{{ */
841 {
842 	char *res;
843 
844 	spprintf(&res, 0, "%s, %s", *list, Z_STRVAL_P(entry));
845 	efree(*list);
846 	*list = res;
847 	return ZEND_HASH_APPLY_KEEP;
848 } /* }}} */
849 
850 /* {{{ PHP_MINFO(spl)
851  */
PHP_MINFO_FUNCTION(spl)852 PHP_MINFO_FUNCTION(spl)
853 {
854 	zval list;
855 	char *strg;
856 
857 	php_info_print_table_start();
858 	php_info_print_table_header(2, "SPL support",        "enabled");
859 
860 	array_init(&list);
861 	SPL_LIST_CLASSES(&list, 0, 1, ZEND_ACC_INTERFACE)
862 	strg = estrdup("");
863 	zend_hash_apply_with_argument(Z_ARRVAL_P(&list), (apply_func_arg_t)spl_build_class_list_string, &strg);
864 	zval_dtor(&list);
865 	php_info_print_table_row(2, "Interfaces", strg + 2);
866 	efree(strg);
867 
868 	array_init(&list);
869 	SPL_LIST_CLASSES(&list, 0, -1, ZEND_ACC_INTERFACE)
870 	strg = estrdup("");
871 	zend_hash_apply_with_argument(Z_ARRVAL_P(&list), (apply_func_arg_t)spl_build_class_list_string, &strg);
872 	zval_dtor(&list);
873 	php_info_print_table_row(2, "Classes", strg + 2);
874 	efree(strg);
875 
876 	php_info_print_table_end();
877 }
878 /* }}} */
879 
880 /* {{{ arginfo */
881 ZEND_BEGIN_ARG_INFO_EX(arginfo_iterator_to_array, 0, 0, 1)
882 	ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0)
883 	ZEND_ARG_INFO(0, use_keys)
884 ZEND_END_ARG_INFO();
885 
886 ZEND_BEGIN_ARG_INFO(arginfo_iterator, 0)
887 	ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0)
888 ZEND_END_ARG_INFO();
889 
890 ZEND_BEGIN_ARG_INFO_EX(arginfo_iterator_apply, 0, 0, 2)
891 	ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0)
892 	ZEND_ARG_INFO(0, function)
893 	ZEND_ARG_ARRAY_INFO(0, args, 1)
894 ZEND_END_ARG_INFO();
895 
896 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_parents, 0, 0, 1)
897 	ZEND_ARG_INFO(0, instance)
898 	ZEND_ARG_INFO(0, autoload)
899 ZEND_END_ARG_INFO()
900 
901 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_implements, 0, 0, 1)
902 	ZEND_ARG_INFO(0, what)
903 	ZEND_ARG_INFO(0, autoload)
904 ZEND_END_ARG_INFO()
905 
906 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_uses, 0, 0, 1)
907 	ZEND_ARG_INFO(0, what)
908 	ZEND_ARG_INFO(0, autoload)
909 ZEND_END_ARG_INFO()
910 
911 
912 ZEND_BEGIN_ARG_INFO(arginfo_spl_classes, 0)
913 ZEND_END_ARG_INFO()
914 
915 ZEND_BEGIN_ARG_INFO(arginfo_spl_autoload_functions, 0)
916 ZEND_END_ARG_INFO()
917 
918 ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_autoload, 0, 0, 1)
919 	ZEND_ARG_INFO(0, class_name)
920 	ZEND_ARG_INFO(0, file_extensions)
921 ZEND_END_ARG_INFO()
922 
923 ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_autoload_extensions, 0, 0, 0)
924 	ZEND_ARG_INFO(0, file_extensions)
925 ZEND_END_ARG_INFO()
926 
927 ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_autoload_call, 0, 0, 1)
928 	ZEND_ARG_INFO(0, class_name)
929 ZEND_END_ARG_INFO()
930 
931 ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_autoload_register, 0, 0, 0)
932 	ZEND_ARG_INFO(0, autoload_function)
933 	ZEND_ARG_INFO(0, throw)
934 	ZEND_ARG_INFO(0, prepend)
935 ZEND_END_ARG_INFO()
936 
937 ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_autoload_unregister, 0, 0, 1)
938 	ZEND_ARG_INFO(0, autoload_function)
939 ZEND_END_ARG_INFO()
940 
941 ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_object_hash, 0, 0, 1)
942 	ZEND_ARG_INFO(0, obj)
943 ZEND_END_ARG_INFO()
944 
945 ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_object_id, 0, 0, 1)
946 	ZEND_ARG_INFO(0, obj)
947 ZEND_END_ARG_INFO()
948 /* }}} */
949 
950 /* {{{ spl_functions
951  */
952 const zend_function_entry spl_functions[] = {
953 	PHP_FE(spl_classes,             arginfo_spl_classes)
954 	PHP_FE(spl_autoload,            arginfo_spl_autoload)
955 	PHP_FE(spl_autoload_extensions, arginfo_spl_autoload_extensions)
956 	PHP_FE(spl_autoload_register,   arginfo_spl_autoload_register)
957 	PHP_FE(spl_autoload_unregister, arginfo_spl_autoload_unregister)
958 	PHP_FE(spl_autoload_functions,  arginfo_spl_autoload_functions)
959 	PHP_FE(spl_autoload_call,       arginfo_spl_autoload_call)
960 	PHP_FE(class_parents,           arginfo_class_parents)
961 	PHP_FE(class_implements,        arginfo_class_implements)
962 	PHP_FE(class_uses,              arginfo_class_uses)
963 	PHP_FE(spl_object_hash,         arginfo_spl_object_hash)
964 	PHP_FE(spl_object_id,           arginfo_spl_object_id)
965 #ifdef SPL_ITERATORS_H
966 	PHP_FE(iterator_to_array,       arginfo_iterator_to_array)
967 	PHP_FE(iterator_count,          arginfo_iterator)
968 	PHP_FE(iterator_apply,          arginfo_iterator_apply)
969 #endif /* SPL_ITERATORS_H */
970 	PHP_FE_END
971 };
972 /* }}} */
973 
974 /* {{{ PHP_MINIT_FUNCTION(spl)
975  */
PHP_MINIT_FUNCTION(spl)976 PHP_MINIT_FUNCTION(spl)
977 {
978 	PHP_MINIT(spl_exceptions)(INIT_FUNC_ARGS_PASSTHRU);
979 	PHP_MINIT(spl_iterators)(INIT_FUNC_ARGS_PASSTHRU);
980 	PHP_MINIT(spl_array)(INIT_FUNC_ARGS_PASSTHRU);
981 	PHP_MINIT(spl_directory)(INIT_FUNC_ARGS_PASSTHRU);
982 	PHP_MINIT(spl_dllist)(INIT_FUNC_ARGS_PASSTHRU);
983 	PHP_MINIT(spl_heap)(INIT_FUNC_ARGS_PASSTHRU);
984 	PHP_MINIT(spl_fixedarray)(INIT_FUNC_ARGS_PASSTHRU);
985 	PHP_MINIT(spl_observer)(INIT_FUNC_ARGS_PASSTHRU);
986 
987 	return SUCCESS;
988 }
989 /* }}} */
990 
PHP_RINIT_FUNCTION(spl)991 PHP_RINIT_FUNCTION(spl) /* {{{ */
992 {
993 	SPL_G(autoload_extensions) = NULL;
994 	SPL_G(autoload_functions) = NULL;
995 	SPL_G(hash_mask_init) = 0;
996 	return SUCCESS;
997 } /* }}} */
998 
PHP_RSHUTDOWN_FUNCTION(spl)999 PHP_RSHUTDOWN_FUNCTION(spl) /* {{{ */
1000 {
1001 	if (SPL_G(autoload_extensions)) {
1002 		zend_string_release(SPL_G(autoload_extensions));
1003 		SPL_G(autoload_extensions) = NULL;
1004 	}
1005 	if (SPL_G(autoload_functions)) {
1006 		zend_hash_destroy(SPL_G(autoload_functions));
1007 		FREE_HASHTABLE(SPL_G(autoload_functions));
1008 		SPL_G(autoload_functions) = NULL;
1009 	}
1010 	if (SPL_G(hash_mask_init)) {
1011 		SPL_G(hash_mask_init) = 0;
1012 	}
1013 	return SUCCESS;
1014 } /* }}} */
1015 
1016 /* {{{ spl_module_entry
1017  */
1018 zend_module_entry spl_module_entry = {
1019 	STANDARD_MODULE_HEADER,
1020 	"SPL",
1021 	spl_functions,
1022 	PHP_MINIT(spl),
1023 	NULL,
1024 	PHP_RINIT(spl),
1025 	PHP_RSHUTDOWN(spl),
1026 	PHP_MINFO(spl),
1027 	PHP_SPL_VERSION,
1028 	PHP_MODULE_GLOBALS(spl),
1029 	PHP_GINIT(spl),
1030 	NULL,
1031 	NULL,
1032 	STANDARD_MODULE_PROPERTIES_EX
1033 };
1034 /* }}} */
1035 
1036 /*
1037  * Local variables:
1038  * tab-width: 4
1039  * c-basic-offset: 4
1040  * End:
1041  * vim600: fdm=marker
1042  * vim: noet sw=4 ts=4
1043  */
1044