1 : /*
2 : +----------------------------------------------------------------------+
3 : | PHP Version 6 |
4 : +----------------------------------------------------------------------+
5 : | Copyright (c) 1997-2009 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: php_spl.c 282591 2009-06-22 18:14:14Z cseiler $ */
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_heap.h"
39 : #include "spl_fixedarray.h"
40 : #include "zend_exceptions.h"
41 : #include "zend_interfaces.h"
42 : #include "ext/standard/php_rand.h"
43 : #include "ext/standard/php_lcg.h"
44 : #include "main/snprintf.h"
45 :
46 : #ifdef COMPILE_DL_SPL
47 : ZEND_GET_MODULE(spl)
48 : #endif
49 :
50 : ZEND_DECLARE_MODULE_GLOBALS(spl)
51 :
52 : /* {{{ PHP_GINIT_FUNCTION
53 : */
54 : static PHP_GINIT_FUNCTION(spl)
55 17007 : {
56 17007 : ZVAL_NULL(&spl_globals->autoload_extensions);
57 17007 : spl_globals->autoload_functions = NULL;
58 17007 : spl_globals->autoload_running = 0;
59 17007 : }
60 : /* }}} */
61 :
62 : static zend_class_entry * spl_find_ce_by_name(zend_uchar ztype, zstr name, int len, zend_bool autoload TSRMLS_DC)
63 36 : {
64 : zend_class_entry **ce;
65 : int found;
66 :
67 36 : if (!autoload) {
68 : zstr lc_name;
69 :
70 12 : lc_name = zend_u_str_tolower_dup(ztype, name, len);
71 12 : found = zend_u_hash_find(EG(class_table), ztype, lc_name, len +1, (void **) &ce);
72 12 : efree(lc_name.v);
73 : } else {
74 24 : found = zend_u_lookup_class(ztype, name, len, &ce TSRMLS_CC);
75 : }
76 36 : if (found != SUCCESS) {
77 8 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Class %v does not exist%s", name, autoload ? " and could not be loaded" : "");
78 8 : return NULL;
79 : }
80 :
81 28 : return *ce;
82 : }
83 :
84 : /* {{{ proto array class_parents(object instance [, boolean autoload = true]) U
85 : Return an array containing the names of all parent classes */
86 : PHP_FUNCTION(class_parents)
87 8 : {
88 : zval *obj;
89 : zend_class_entry *parent_class, *ce;
90 8 : zend_bool autoload = 1;
91 :
92 8 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &obj, &autoload) == FAILURE) {
93 0 : RETURN_FALSE;
94 : }
95 :
96 8 : if (Z_TYPE_P(obj) != IS_OBJECT && Z_TYPE_P(obj) != IS_STRING && Z_TYPE_P(obj) != IS_UNICODE) {
97 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "object or string expected");
98 0 : RETURN_FALSE;
99 : }
100 :
101 11 : if (Z_TYPE_P(obj) == IS_STRING || Z_TYPE_P(obj) == IS_UNICODE) {
102 5 : if (NULL == (ce = spl_find_ce_by_name(Z_TYPE_P(obj), Z_UNIVAL_P(obj), Z_UNILEN_P(obj), autoload TSRMLS_CC))) {
103 2 : RETURN_FALSE;
104 : }
105 : } else {
106 3 : ce = Z_OBJCE_P(obj);
107 : }
108 :
109 6 : array_init(return_value);
110 6 : parent_class = ce->parent;
111 20 : while (parent_class) {
112 8 : spl_add_class_name(return_value, parent_class, 0, 0 TSRMLS_CC);
113 8 : parent_class = parent_class->parent;
114 : }
115 : }
116 : /* }}} */
117 :
118 : /* {{{ proto array class_implements(mixed what [, bool autoload ]) U
119 : Return all classes and interfaces implemented by SPL */
120 : PHP_FUNCTION(class_implements)
121 68 : {
122 : zval *obj;
123 68 : zend_bool autoload = 1;
124 : zend_class_entry *ce;
125 :
126 68 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &obj, &autoload) == FAILURE) {
127 7 : RETURN_FALSE;
128 : }
129 61 : if (Z_TYPE_P(obj) != IS_OBJECT && Z_TYPE_P(obj) != IS_STRING && Z_TYPE_P(obj) != IS_UNICODE) {
130 22 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "object or string expected");
131 22 : RETURN_FALSE;
132 : }
133 :
134 64 : if (Z_TYPE_P(obj) == IS_STRING || Z_TYPE_P(obj) == IS_UNICODE) {
135 31 : if (NULL == (ce = spl_find_ce_by_name(Z_TYPE_P(obj), Z_UNIVAL_P(obj), Z_UNILEN_P(obj), autoload TSRMLS_CC))) {
136 6 : RETURN_FALSE;
137 : }
138 : } else {
139 8 : ce = Z_OBJCE_P(obj);
140 : }
141 :
142 33 : array_init(return_value);
143 33 : spl_add_interfaces(return_value, ce, 1, ZEND_ACC_INTERFACE TSRMLS_CC);
144 : }
145 : /* }}} */
146 :
147 : #define SPL_ADD_CLASS(class_name, z_list, sub, allow, ce_flags) \
148 : spl_add_classes(spl_ce_ ## class_name, z_list, sub, allow, ce_flags TSRMLS_CC)
149 :
150 : #define SPL_LIST_CLASSES(z_list, sub, allow, ce_flags) \
151 : SPL_ADD_CLASS(AppendIterator, z_list, sub, allow, ce_flags); \
152 : SPL_ADD_CLASS(ArrayIterator, z_list, sub, allow, ce_flags); \
153 : SPL_ADD_CLASS(ArrayObject, z_list, sub, allow, ce_flags); \
154 : SPL_ADD_CLASS(BadFunctionCallException, z_list, sub, allow, ce_flags); \
155 : SPL_ADD_CLASS(BadMethodCallException, z_list, sub, allow, ce_flags); \
156 : SPL_ADD_CLASS(CachingIterator, z_list, sub, allow, ce_flags); \
157 : SPL_ADD_CLASS(Countable, z_list, sub, allow, ce_flags); \
158 : SPL_ADD_CLASS(DirectoryIterator, z_list, sub, allow, ce_flags); \
159 : SPL_ADD_CLASS(DomainException, z_list, sub, allow, ce_flags); \
160 : SPL_ADD_CLASS(EmptyIterator, z_list, sub, allow, ce_flags); \
161 : SPL_ADD_CLASS(FilesystemIterator, z_list, sub, allow, ce_flags); \
162 : SPL_ADD_CLASS(FilterIterator, z_list, sub, allow, ce_flags); \
163 : SPL_ADD_CLASS(GlobIterator, z_list, sub, allow, ce_flags); \
164 : SPL_ADD_CLASS(InfiniteIterator, z_list, sub, allow, ce_flags); \
165 : SPL_ADD_CLASS(InvalidArgumentException, z_list, sub, allow, ce_flags); \
166 : SPL_ADD_CLASS(IteratorIterator, z_list, sub, allow, ce_flags); \
167 : SPL_ADD_CLASS(LengthException, z_list, sub, allow, ce_flags); \
168 : SPL_ADD_CLASS(LimitIterator, z_list, sub, allow, ce_flags); \
169 : SPL_ADD_CLASS(LogicException, z_list, sub, allow, ce_flags); \
170 : SPL_ADD_CLASS(MultipleIterator, z_list, sub, allow, ce_flags); \
171 : SPL_ADD_CLASS(NoRewindIterator, z_list, sub, allow, ce_flags); \
172 : SPL_ADD_CLASS(OuterIterator, z_list, sub, allow, ce_flags); \
173 : SPL_ADD_CLASS(OutOfBoundsException, z_list, sub, allow, ce_flags); \
174 : SPL_ADD_CLASS(OutOfRangeException, z_list, sub, allow, ce_flags); \
175 : SPL_ADD_CLASS(OverflowException, z_list, sub, allow, ce_flags); \
176 : SPL_ADD_CLASS(ParentIterator, z_list, sub, allow, ce_flags); \
177 : SPL_ADD_CLASS(RangeException, z_list, sub, allow, ce_flags); \
178 : SPL_ADD_CLASS(RecursiveArrayIterator, z_list, sub, allow, ce_flags); \
179 : SPL_ADD_CLASS(RecursiveCachingIterator, z_list, sub, allow, ce_flags); \
180 : SPL_ADD_CLASS(RecursiveDirectoryIterator, z_list, sub, allow, ce_flags); \
181 : SPL_ADD_CLASS(RecursiveFilterIterator, z_list, sub, allow, ce_flags); \
182 : SPL_ADD_CLASS(RecursiveIterator, z_list, sub, allow, ce_flags); \
183 : SPL_ADD_CLASS(RecursiveIteratorIterator, z_list, sub, allow, ce_flags); \
184 : SPL_ADD_CLASS(RecursiveRegexIterator, z_list, sub, allow, ce_flags); \
185 : SPL_ADD_CLASS(RecursiveTreeIterator, z_list, sub, allow, ce_flags); \
186 : SPL_ADD_CLASS(RegexIterator, z_list, sub, allow, ce_flags); \
187 : SPL_ADD_CLASS(RuntimeException, z_list, sub, allow, ce_flags); \
188 : SPL_ADD_CLASS(SeekableIterator, z_list, sub, allow, ce_flags); \
189 : SPL_ADD_CLASS(SplDoublyLinkedList, z_list, sub, allow, ce_flags); \
190 : SPL_ADD_CLASS(SplFileInfo, z_list, sub, allow, ce_flags); \
191 : SPL_ADD_CLASS(SplFileObject, z_list, sub, allow, ce_flags); \
192 : SPL_ADD_CLASS(SplFixedArray, z_list, sub, allow, ce_flags); \
193 : SPL_ADD_CLASS(SplHeap, z_list, sub, allow, ce_flags); \
194 : SPL_ADD_CLASS(SplMinHeap, z_list, sub, allow, ce_flags); \
195 : SPL_ADD_CLASS(SplMaxHeap, z_list, sub, allow, ce_flags); \
196 : SPL_ADD_CLASS(SplObjectStorage, z_list, sub, allow, ce_flags); \
197 : SPL_ADD_CLASS(SplObserver, z_list, sub, allow, ce_flags); \
198 : SPL_ADD_CLASS(SplPriorityQueue, z_list, sub, allow, ce_flags); \
199 : SPL_ADD_CLASS(SplQueue, z_list, sub, allow, ce_flags); \
200 : SPL_ADD_CLASS(SplStack, z_list, sub, allow, ce_flags); \
201 : SPL_ADD_CLASS(SplSubject, z_list, sub, allow, ce_flags); \
202 : SPL_ADD_CLASS(SplTempFileObject, z_list, sub, allow, ce_flags); \
203 : SPL_ADD_CLASS(UnderflowException, z_list, sub, allow, ce_flags); \
204 : SPL_ADD_CLASS(UnexpectedValueException, z_list, sub, allow, ce_flags); \
205 :
206 : /* {{{ proto array spl_classes() U
207 : Return an array containing the names of all clsses and interfaces defined in SPL */
208 : PHP_FUNCTION(spl_classes)
209 1 : {
210 1 : array_init(return_value);
211 :
212 1 : SPL_LIST_CLASSES(return_value, 0, 0, 0)
213 1 : }
214 : /* }}} */
215 :
216 : int spl_autoload(const zstr class_name, const zstr lc_name, int class_name_len, const zstr file_extension TSRMLS_DC) /* {{{ */
217 15 : {
218 : char *class_file;
219 : int class_file_len;
220 15 : int dummy = 1;
221 : zend_file_handle file_handle;
222 : zend_op_array *new_op_array;
223 15 : zval *result = NULL;
224 : int ret;
225 :
226 : /* UTODO: We want the stream to accept a zstr for opening */
227 15 : class_file_len = spprintf(&class_file, 0, "%v%v", lc_name, file_extension);
228 :
229 15 : ret = php_stream_open_for_zend_ex(class_file, &file_handle, ENFORCE_SAFE_MODE|USE_PATH|STREAM_OPEN_FOR_INCLUDE TSRMLS_CC);
230 :
231 15 : if (ret == SUCCESS) {
232 10 : if (!file_handle.opened_path) {
233 0 : file_handle.opened_path = estrndup(class_file, class_file_len);
234 : }
235 10 : if (zend_hash_add(&EG(included_files), file_handle.opened_path, strlen(file_handle.opened_path)+1, (void *)&dummy, sizeof(int), NULL)==SUCCESS) {
236 5 : new_op_array = zend_compile_file(&file_handle, ZEND_REQUIRE TSRMLS_CC);
237 5 : zend_destroy_file_handle(&file_handle TSRMLS_CC);
238 : } else {
239 5 : new_op_array = NULL;
240 5 : zend_file_handle_dtor(&file_handle TSRMLS_CC);
241 : }
242 10 : if (new_op_array) {
243 5 : EG(return_value_ptr_ptr) = &result;
244 5 : EG(active_op_array) = new_op_array;
245 5 : if (!EG(active_symbol_table)) {
246 0 : zend_rebuild_symbol_table(TSRMLS_C);
247 : }
248 :
249 5 : zend_execute(new_op_array TSRMLS_CC);
250 :
251 5 : destroy_op_array(new_op_array TSRMLS_CC);
252 5 : efree(new_op_array);
253 5 : if (!EG(exception)) {
254 5 : if (EG(return_value_ptr_ptr)) {
255 5 : zval_ptr_dtor(EG(return_value_ptr_ptr));
256 : }
257 : }
258 :
259 5 : efree(class_file);
260 5 : return zend_u_hash_exists(EG(class_table), IS_UNICODE, lc_name, class_name_len+1);
261 : }
262 : }
263 10 : efree(class_file);
264 10 : return 0;
265 : } /* }}} */
266 :
267 : /* {{{ proto void spl_autoload(string class_name [, string file_extensions]) U
268 : Default implementation for __autoload() */
269 : PHP_FUNCTION(spl_autoload)
270 10 : {
271 : zstr class_name, lc_name;
272 10 : zstr file_exts = Z_UNIVAL(SPL_G(autoload_extensions));
273 10 : int class_name_len, file_exts_len = Z_UNILEN(SPL_G(autoload_extensions)), found = 0;
274 : zstr copy, pos1, pos2;
275 10 : zval **original_return_value = EG(return_value_ptr_ptr);
276 10 : zend_op **original_opline_ptr = EG(opline_ptr);
277 10 : zend_op_array *original_active_op_array = EG(active_op_array);
278 :
279 10 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "x|x", &class_name, &class_name_len, &file_exts, &file_exts_len) == FAILURE) {
280 0 : RETURN_FALSE;
281 : }
282 :
283 10 : copy = pos1 = ezstrndup(IS_UNICODE, file_exts, file_exts_len);
284 10 : lc_name = zend_u_str_tolower_dup(IS_UNICODE, class_name, class_name_len);
285 34 : while(pos1.v && *pos1.u && !EG(exception)) {
286 15 : EG(return_value_ptr_ptr) = original_return_value;
287 15 : EG(opline_ptr) = original_opline_ptr;
288 15 : EG(active_op_array) = original_active_op_array;
289 15 : pos2.u = u_strchr(pos1.u, ',');
290 15 : if (pos2.u) {
291 7 : *pos2.u = '\0';
292 : }
293 15 : if (spl_autoload(class_name, lc_name, class_name_len, pos1 TSRMLS_CC)) {
294 1 : found = 1;
295 1 : break; /* loaded */
296 : }
297 14 : if (!pos2.v) {
298 7 : pos1.v = NULL;
299 : } else {
300 7 : pos1.u = pos2.u + 1;
301 : }
302 : }
303 10 : efree(lc_name.v);
304 :
305 10 : if (copy.v) {
306 10 : efree(copy.v);
307 : }
308 :
309 10 : EG(return_value_ptr_ptr) = original_return_value;
310 10 : EG(opline_ptr) = original_opline_ptr;
311 10 : EG(active_op_array) = original_active_op_array;
312 :
313 10 : if (!found && !SPL_G(autoload_running)) {
314 : /* For internal errors, we generate E_ERROR, for direct calls an exception is thrown.
315 : * The "scope" is determined by an opcode, if it is ZEND_FETCH_CLASS we know function was called indirectly by
316 : * the Zend engine.
317 : */
318 8 : if (active_opline->opcode != ZEND_FETCH_CLASS) {
319 7 : zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Class %v could not be loaded", class_name.u);
320 : } else {
321 1 : php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %v could not be loaded", class_name.u);
322 : }
323 : }
324 : } /* }}} */
325 :
326 : /* {{{ proto string spl_autoload_extensions([string file_extensions]) U
327 : Register and return default file extensions for spl_autoload */
328 : PHP_FUNCTION(spl_autoload_extensions)
329 4 : {
330 : zstr file_exts;
331 : int file_exts_len;
332 4 : zval *global = &SPL_G(autoload_extensions);
333 :
334 4 : if (ZEND_NUM_ARGS() > 0) {
335 3 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "x", &file_exts, &file_exts_len) == FAILURE) {
336 0 : return;
337 : }
338 3 : zval_dtor(global);
339 3 : ZVAL_ZSTRL(global, IS_UNICODE, file_exts, file_exts_len, 1);
340 : }
341 :
342 4 : RETURN_ZVAL(global, 1, 0);
343 : } /* }}} */
344 :
345 : typedef struct {
346 : zend_function *func_ptr;
347 : zval *obj;
348 : zval *closure;
349 : zend_class_entry *ce;
350 : } autoload_func_info;
351 :
352 : static void autoload_func_info_dtor(autoload_func_info *alfi)
353 45 : {
354 45 : if (alfi->obj) {
355 13 : zval_ptr_dtor(&alfi->obj);
356 : }
357 45 : if (alfi->closure) {
358 10 : zval_ptr_dtor(&alfi->closure);
359 : }
360 45 : }
361 :
362 : /* {{{ proto void spl_autoload_call(string class_name) U
363 : Try all registerd autoload function to load the requested class */
364 : PHP_FUNCTION(spl_autoload_call)
365 25 : {
366 25 : zval *zclass_name, *retval = NULL;
367 : int class_name_len, func_name_type;
368 : zstr class_name, func_name, lc_name;
369 : uint func_name_len;
370 : ulong dummy;
371 : HashPosition function_pos;
372 : autoload_func_info *alfi;
373 :
374 25 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "x", &class_name, &class_name_len) == FAILURE) {
375 0 : return;
376 : }
377 :
378 25 : MAKE_STD_ZVAL(zclass_name);
379 25 : ZVAL_ZSTRL(zclass_name, IS_UNICODE, class_name, class_name_len, 1);
380 25 : if (SPL_G(autoload_functions)) {
381 25 : int l_autoload_running = SPL_G(autoload_running);
382 25 : SPL_G(autoload_running) = 1;
383 25 : lc_name = zend_u_str_tolower_dup(IS_UNICODE, class_name, class_name_len);
384 25 : zend_hash_internal_pointer_reset_ex(SPL_G(autoload_functions), &function_pos);
385 82 : while(zend_hash_has_more_elements_ex(SPL_G(autoload_functions), &function_pos) == SUCCESS) {
386 41 : func_name_type = zend_hash_get_current_key_ex(SPL_G(autoload_functions), &func_name, &func_name_len, &dummy, 0, &function_pos);
387 41 : zend_hash_get_current_data_ex(SPL_G(autoload_functions), (void **) &alfi, &function_pos);
388 41 : zend_u_call_method(alfi->obj ? &alfi->obj : NULL, alfi->ce, &alfi->func_ptr, func_name_type, func_name, func_name_len, &retval, 1, zclass_name, NULL TSRMLS_CC);
389 41 : zend_exception_save(TSRMLS_C);
390 41 : if (retval) {
391 28 : zval_ptr_dtor(&retval);
392 : }
393 41 : if (zend_u_hash_exists(EG(class_table), IS_UNICODE, lc_name, class_name_len+1)) {
394 9 : break;
395 : }
396 32 : zend_hash_move_forward_ex(SPL_G(autoload_functions), &function_pos);
397 : }
398 25 : zend_exception_restore(TSRMLS_C);
399 25 : efree(lc_name.v);
400 25 : SPL_G(autoload_running) = l_autoload_running;
401 : } else {
402 : /* do not use or overwrite &EG(autoload_func) here */
403 0 : zend_call_method_with_1_params(NULL, NULL, NULL, "spl_autoload", NULL, zclass_name);
404 : }
405 25 : zval_ptr_dtor(&zclass_name);
406 : } /* }}} */
407 :
408 : #define HT_MOVE_TAIL_TO_HEAD(ht) \
409 : (ht)->pListTail->pListNext = (ht)->pListHead; \
410 : (ht)->pListHead = (ht)->pListTail; \
411 : (ht)->pListTail = (ht)->pListHead->pListLast; \
412 : (ht)->pListHead->pListNext->pListLast = (ht)->pListHead;\
413 : (ht)->pListTail->pListNext = NULL; \
414 : (ht)->pListHead->pListLast = NULL;
415 :
416 : /* {{{ proto bool spl_autoload_register([mixed autoload_function = "spl_autoload" [, throw = true [, prepend = false]]]) U
417 : Register given function as __autoload() implementation */
418 : PHP_FUNCTION(spl_autoload_register)
419 67 : {
420 67 : char *error = NULL;
421 : zval zfunc_name, ztmp;
422 67 : zval *zcallable = NULL;
423 67 : zend_bool do_throw = 1;
424 67 : zend_bool prepend = 0;
425 : zend_function *spl_func_ptr;
426 : autoload_func_info alfi;
427 : zval *obj_ptr;
428 : zend_fcall_info_cache fcc;
429 :
430 67 : if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "|zbb", &zcallable, &do_throw, &prepend) == FAILURE) {
431 0 : return;
432 : }
433 :
434 67 : if (ZEND_NUM_ARGS()) {
435 63 : if (Z_TYPE_P(zcallable) == IS_STRING) {
436 0 : if (Z_STRLEN_P(zcallable) == sizeof("spl_autoload_call") - 1) {
437 0 : if (!zend_binary_strcasecmp(Z_STRVAL_P(zcallable), sizeof("spl_autoload_call"), "spl_autoload_call", sizeof("spl_autoload_call"))) {
438 0 : if (do_throw) {
439 0 : zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Function spl_autoload_call() cannot be registered");
440 : }
441 0 : RETURN_FALSE;
442 : }
443 : }
444 63 : } else if (Z_TYPE_P(zcallable) == IS_UNICODE) {
445 30 : ZVAL_ASCII_STRINGL(&ztmp, "spl_autoload_call", sizeof("spl_autoload_call")-1, 1);
446 30 : if (zend_u_binary_zval_strcmp(&ztmp, zcallable)) {
447 30 : if (!zend_binary_strcasecmp(Z_STRVAL_P(zcallable), sizeof("spl_autoload_call"), "spl_autoload_call", sizeof("spl_autoload_call"))) {
448 0 : if (do_throw) {
449 0 : zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Function spl_autoload_call() cannot be registered");
450 : }
451 0 : zval_dtor(&ztmp);
452 0 : RETURN_FALSE;
453 : }
454 : }
455 30 : zval_dtor(&ztmp);
456 : }
457 :
458 63 : if (!zend_is_callable_ex(zcallable, NULL, IS_CALLABLE_STRICT, &zfunc_name, &fcc, &error TSRMLS_CC)) {
459 12 : alfi.ce = fcc.calling_scope;
460 12 : alfi.func_ptr = fcc.function_handler;
461 12 : obj_ptr = fcc.object_ptr;
462 12 : if (Z_TYPE_P(zcallable) == IS_ARRAY) {
463 7 : if (!obj_ptr && alfi.func_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) {
464 3 : if (do_throw) {
465 3 : zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Passed array specifies a non static method but no object (%s)", error);
466 : }
467 3 : if (error) {
468 3 : efree(error);
469 : }
470 3 : zval_dtor(&zfunc_name);
471 3 : RETURN_FALSE;
472 : }
473 4 : else if (do_throw) {
474 4 : zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Passed array does not specify %s %smethod (%s)", alfi.func_ptr ? "a callable" : "an existing", !obj_ptr ? "static " : "", error);
475 : }
476 4 : if (error) {
477 4 : efree(error);
478 : }
479 4 : zval_dtor(&zfunc_name);
480 4 : RETURN_FALSE;
481 5 : } else if (Z_TYPE_P(zcallable) == IS_STRING || Z_TYPE_P(zcallable) == IS_UNICODE) {
482 5 : if (do_throw) {
483 5 : zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Function '%R' not %s (%s)", Z_TYPE_P(zcallable), Z_UNIVAL_P(zcallable), alfi.func_ptr ? "callable" : "found", error);
484 : }
485 5 : if (error) {
486 5 : efree(error);
487 : }
488 5 : zval_dtor(&zfunc_name);
489 5 : RETURN_FALSE;
490 : } else {
491 0 : if (do_throw) {
492 0 : zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Illegal value passed (%s)", error);
493 : }
494 0 : if (error) {
495 0 : efree(error);
496 : }
497 0 : zval_dtor(&zfunc_name);
498 0 : RETURN_FALSE;
499 : }
500 : }
501 51 : alfi.closure = NULL;
502 51 : alfi.ce = fcc.calling_scope;
503 51 : alfi.func_ptr = fcc.function_handler;
504 51 : obj_ptr = fcc.object_ptr;
505 :
506 51 : zend_u_str_tolower(Z_TYPE(zfunc_name), Z_UNIVAL(zfunc_name), Z_UNILEN(zfunc_name));
507 :
508 51 : if (Z_TYPE_P(zcallable) == IS_OBJECT) {
509 : zstr lc_name;
510 :
511 12 : size_t func_name_len = Z_UNISIZE(zfunc_name);
512 :
513 12 : alfi.closure = zcallable;
514 12 : Z_ADDREF_P(zcallable);
515 :
516 12 : lc_name.v = Z_UNIVAL(zfunc_name).v = erealloc(Z_UNIVAL(zfunc_name).v, func_name_len + 2 + sizeof(zend_object_handle));
517 12 : memcpy(lc_name.s + func_name_len, &Z_OBJ_HANDLE_P(zcallable), sizeof(zend_object_handle));
518 12 : func_name_len += sizeof(zend_object_handle);
519 12 : if (Z_TYPE(zfunc_name) == IS_UNICODE) {
520 12 : func_name_len /= sizeof(UChar);
521 12 : Z_STRLEN(zfunc_name) = func_name_len;
522 12 : lc_name.u[func_name_len] = 0;
523 : } else {
524 0 : Z_STRLEN(zfunc_name) = func_name_len;
525 0 : lc_name.s[func_name_len] = '\0';
526 : }
527 : }
528 51 : if (error) {
529 0 : efree(error);
530 : }
531 :
532 51 : if (SPL_G(autoload_functions) && zend_u_hash_exists(SPL_G(autoload_functions), Z_TYPE(zfunc_name), Z_UNIVAL(zfunc_name), Z_UNILEN(zfunc_name)+1)) {
533 6 : if (alfi.closure) {
534 1 : Z_DELREF_P(zcallable);
535 : }
536 6 : goto skip;
537 : }
538 :
539 59 : if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) {
540 : /* add object id to the hash to ensure uniqueness, for more reference look at bug #40091 */
541 : zstr lc_name;
542 14 : size_t func_name_len = Z_UNISIZE(zfunc_name);
543 14 : lc_name.v = Z_UNIVAL(zfunc_name).v = erealloc(Z_UNIVAL(zfunc_name).v, func_name_len + 2 + sizeof(zend_object_handle));
544 14 : memcpy(lc_name.s + func_name_len, &Z_OBJ_HANDLE_P(obj_ptr), sizeof(zend_object_handle));
545 14 : func_name_len += sizeof(zend_object_handle);
546 14 : alfi.obj = obj_ptr;
547 14 : Z_ADDREF_P(alfi.obj);
548 14 : if (Z_TYPE(zfunc_name) == IS_UNICODE) {
549 14 : func_name_len /= sizeof(UChar);
550 14 : Z_STRLEN(zfunc_name) = func_name_len;
551 14 : lc_name.u[func_name_len] = 0;
552 : } else {
553 0 : Z_STRLEN(zfunc_name) = func_name_len;
554 0 : lc_name.s[func_name_len] = '\0';
555 : }
556 : } else {
557 31 : alfi.obj = NULL;
558 : }
559 :
560 45 : if (!SPL_G(autoload_functions)) {
561 21 : ALLOC_HASHTABLE(SPL_G(autoload_functions));
562 21 : zend_u_hash_init(SPL_G(autoload_functions), 1, NULL, (dtor_func_t) autoload_func_info_dtor, 0, UG(unicode));
563 : }
564 :
565 45 : zend_hash_find(EG(function_table), "spl_autoload", sizeof("spl_autoload"), (void **) &spl_func_ptr);
566 :
567 45 : if (EG(autoload_func) == spl_func_ptr) { /* registered already, so we insert that first */
568 : autoload_func_info spl_alfi;
569 :
570 1 : spl_alfi.func_ptr = spl_func_ptr;
571 1 : spl_alfi.obj = NULL;
572 1 : spl_alfi.ce = NULL;
573 1 : spl_alfi.closure = NULL;
574 1 : zend_hash_add(SPL_G(autoload_functions), "spl_autoload", sizeof("spl_autoload"), &spl_alfi, sizeof(autoload_func_info), NULL);
575 1 : if (prepend && SPL_G(autoload_functions)->nNumOfElements > 1) {
576 : /* Move the newly created element to the head of the hashtable */
577 0 : HT_MOVE_TAIL_TO_HEAD(SPL_G(autoload_functions));
578 : }
579 : }
580 :
581 45 : zend_u_hash_add(SPL_G(autoload_functions), Z_TYPE(zfunc_name), Z_UNIVAL(zfunc_name), Z_UNILEN(zfunc_name)+1, &alfi, sizeof(autoload_func_info), NULL);
582 45 : if (prepend && SPL_G(autoload_functions)->nNumOfElements > 1) {
583 : /* Move the newly created element to the head of the hashtable */
584 2 : HT_MOVE_TAIL_TO_HEAD(SPL_G(autoload_functions));
585 : }
586 51 : skip:
587 51 : zval_dtor(&zfunc_name);
588 : }
589 :
590 55 : if (SPL_G(autoload_functions)) {
591 51 : zend_hash_find(EG(function_table), "spl_autoload_call", sizeof("spl_autoload_call"), (void **) &EG(autoload_func));
592 : } else {
593 4 : zend_hash_find(EG(function_table), "spl_autoload", sizeof("spl_autoload"), (void **) &EG(autoload_func));
594 : }
595 55 : RETURN_TRUE;
596 : } /* }}} */
597 :
598 : /* {{{ proto bool spl_autoload_unregister(mixed autoload_function) U
599 : Unregister given function as __autoload() implementation */
600 : PHP_FUNCTION(spl_autoload_unregister)
601 14 : {
602 14 : char *error = NULL;
603 : zval zfunc_name;
604 : zval *zcallable;
605 : zstr lc_name;
606 : size_t lc_name_len;
607 14 : int success = FAILURE;
608 : zend_function *spl_func_ptr;
609 : zval *obj_ptr;
610 : zend_fcall_info_cache fcc;
611 :
612 14 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zcallable) == FAILURE) {
613 0 : return;
614 : }
615 :
616 14 : if (!zend_is_callable_ex(zcallable, NULL, IS_CALLABLE_CHECK_SYNTAX_ONLY, &zfunc_name, &fcc, &error TSRMLS_CC)) {
617 0 : zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Unable to unregister invalid function (%s)", error);
618 0 : if (error) {
619 0 : efree(error);
620 : }
621 0 : zval_dtor(&zfunc_name);
622 0 : RETURN_FALSE;
623 : }
624 14 : obj_ptr = fcc.object_ptr;
625 14 : if (error) {
626 0 : efree(error);
627 : }
628 :
629 14 : lc_name = zend_u_str_tolower_dup(Z_TYPE(zfunc_name), Z_UNIVAL(zfunc_name), Z_UNILEN(zfunc_name));
630 14 : lc_name_len = Z_UNILEN(zfunc_name);
631 :
632 14 : if (Z_TYPE_P(zcallable) == IS_OBJECT) {
633 2 : lc_name_len = Z_UNISIZE(zfunc_name);
634 2 : lc_name.v = erealloc(lc_name.v, lc_name_len + 2 + sizeof(zend_object_handle));
635 2 : memcpy(lc_name.s + lc_name_len, &Z_OBJ_HANDLE_P(zcallable), sizeof(zend_object_handle));
636 2 : lc_name_len += sizeof(zend_object_handle);
637 2 : if (Z_TYPE(zfunc_name) == IS_UNICODE) {
638 2 : lc_name_len /= sizeof(UChar);
639 2 : lc_name.u[lc_name_len] = 0;
640 : } else {
641 0 : lc_name.s[lc_name_len] = '\0';
642 : }
643 : }
644 :
645 14 : if (SPL_G(autoload_functions)) {
646 13 : if ((lc_name_len == sizeof("spl_autoload_call")-1) &&
647 : (ZEND_U_EQUAL(Z_TYPE(zfunc_name), lc_name, lc_name_len, "spl_autoload_call", sizeof("spl_autoload_call")-1))) {
648 : /* remove all */
649 1 : zend_hash_destroy(SPL_G(autoload_functions));
650 1 : FREE_HASHTABLE(SPL_G(autoload_functions));
651 1 : SPL_G(autoload_functions) = NULL;
652 1 : EG(autoload_func) = NULL;
653 1 : success = SUCCESS;
654 : } else {
655 : /* remove specific */
656 11 : success = zend_u_hash_del(SPL_G(autoload_functions), Z_TYPE(zfunc_name), lc_name, lc_name_len+1);
657 11 : if (success != SUCCESS && obj_ptr) {
658 2 : if (Z_TYPE(zfunc_name) == IS_UNICODE) {
659 2 : lc_name_len *= sizeof(UChar);
660 : }
661 2 : lc_name.v = erealloc(lc_name.v, lc_name_len + 2 + sizeof(zend_object_handle));
662 2 : memcpy(lc_name.s + lc_name_len, &Z_OBJ_HANDLE_P(obj_ptr), sizeof(zend_object_handle));
663 2 : lc_name_len += sizeof(zend_object_handle);
664 2 : if (Z_TYPE(zfunc_name) == IS_UNICODE) {
665 2 : lc_name_len /= sizeof(UChar);
666 2 : lc_name.u[lc_name_len] = 0;
667 : } else {
668 0 : lc_name.s[lc_name_len] = '\0';
669 : }
670 2 : success = zend_u_hash_del(SPL_G(autoload_functions), Z_TYPE(zfunc_name), lc_name, lc_name_len+1);
671 : }
672 : }
673 2 : } else if ((lc_name_len == sizeof("spl_autoload")-1) &&
674 : (ZEND_U_EQUAL(Z_TYPE(zfunc_name), lc_name, lc_name_len, "spl_autoload", sizeof("spl_autoload")-1))) {
675 : /* register single spl_autoload() */
676 2 : zend_hash_find(EG(function_table), "spl_autoload", sizeof("spl_autoload"), (void **) &spl_func_ptr);
677 :
678 2 : if (EG(autoload_func) == spl_func_ptr) {
679 2 : success = SUCCESS;
680 2 : EG(autoload_func) = NULL;
681 : }
682 : }
683 :
684 14 : efree(lc_name.v);
685 14 : zval_dtor(&zfunc_name);
686 :
687 14 : RETURN_BOOL(success == SUCCESS);
688 : } /* }}} */
689 :
690 : /* {{{ proto false|array spl_autoload_functions() U
691 : Return all registered __autoload() functionns */
692 : PHP_FUNCTION(spl_autoload_functions)
693 27 : {
694 : zend_function *fptr;
695 : HashPosition function_pos;
696 : autoload_func_info *alfi;
697 :
698 27 : if (!EG(autoload_func)) {
699 4 : if (zend_hash_find(EG(function_table), ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME), (void **) &fptr) == SUCCESS) {
700 0 : array_init(return_value);
701 0 : add_next_index_stringl(return_value, ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME)-1, 1);
702 0 : return;
703 : }
704 4 : RETURN_FALSE;
705 : }
706 :
707 23 : zend_hash_find(EG(function_table), "spl_autoload_call", sizeof("spl_autoload_call"), (void **) &fptr);
708 :
709 23 : if (EG(autoload_func) == fptr) {
710 21 : array_init(return_value);
711 21 : zend_hash_internal_pointer_reset_ex(SPL_G(autoload_functions), &function_pos);
712 63 : while(zend_hash_has_more_elements_ex(SPL_G(autoload_functions), &function_pos) == SUCCESS) {
713 21 : zend_hash_get_current_data_ex(SPL_G(autoload_functions), (void **) &alfi, &function_pos);
714 21 : if (alfi->closure) {
715 3 : Z_ADDREF_P(alfi->closure);
716 3 : add_next_index_zval(return_value, alfi->closure);
717 18 : } else if (alfi->func_ptr->common.scope) {
718 : zval *tmp;
719 9 : MAKE_STD_ZVAL(tmp);
720 9 : array_init(tmp);
721 :
722 9 : if (alfi->obj) {
723 4 : Z_ADDREF_P(alfi->obj);
724 4 : add_next_index_zval(tmp, alfi->obj);
725 : } else {
726 5 : add_next_index_unicode(tmp, alfi->ce->name.u, 1);
727 : }
728 9 : add_next_index_unicode(tmp, alfi->func_ptr->common.function_name.u, 1);
729 9 : add_next_index_zval(return_value, tmp);
730 : } else {
731 9 : add_next_index_unicode(return_value, alfi->func_ptr->common.function_name.u, 1);
732 : }
733 :
734 21 : zend_hash_move_forward_ex(SPL_G(autoload_functions), &function_pos);
735 : }
736 21 : return;
737 : }
738 :
739 2 : array_init(return_value);
740 2 : add_next_index_unicode(return_value, EG(autoload_func)->common.function_name.u, 1);
741 : } /* }}} */
742 :
743 : /* {{{ proto string spl_object_hash(object obj) U
744 : Return hash id for given object */
745 : PHP_FUNCTION(spl_object_hash)
746 3 : {
747 : zval *obj;
748 : char* hash;
749 :
750 3 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) {
751 2 : return;
752 : }
753 :
754 1 : hash = emalloc(33);
755 1 : php_spl_object_hash(obj, hash TSRMLS_CC);
756 :
757 1 : RETVAL_STRING(hash, 0);
758 : }
759 : /* }}} */
760 :
761 : PHPAPI void php_spl_object_hash(zval *obj, char *result TSRMLS_DC) /* {{{*/
762 28 : {
763 : intptr_t hash_handle, hash_handlers;
764 : char *hex;
765 :
766 28 : if (!SPL_G(hash_mask_init)) {
767 6 : if (!BG(mt_rand_is_seeded)) {
768 6 : php_mt_srand(GENERATE_SEED() TSRMLS_CC);
769 : }
770 :
771 6 : SPL_G(hash_mask_handle) = (intptr_t)(php_mt_rand(TSRMLS_C) >> 1);
772 6 : SPL_G(hash_mask_handlers) = (intptr_t)(php_mt_rand(TSRMLS_C) >> 1);
773 6 : SPL_G(hash_mask_init) = 1;
774 : }
775 :
776 28 : hash_handle = SPL_G(hash_mask_handle)^(intptr_t)Z_OBJ_HANDLE_P(obj);
777 28 : hash_handlers = SPL_G(hash_mask_handlers)^(intptr_t)Z_OBJ_HT_P(obj);
778 :
779 28 : spprintf(&hex, 32, "%016x%016x", hash_handle, hash_handlers);
780 :
781 28 : strlcpy(result, hex, 33);
782 28 : efree(hex);
783 28 : }
784 : /* }}} */
785 :
786 : int spl_build_class_list_string(zval **entry, char **list TSRMLS_DC) /* {{{ */
787 2322 : {
788 : char *res;
789 :
790 2322 : spprintf(&res, 0, "%s, %v", *list, Z_STRVAL_PP(entry));
791 2322 : efree(*list);
792 2322 : *list = res;
793 2322 : return ZEND_HASH_APPLY_KEEP;
794 : } /* }}} */
795 :
796 : /* {{{ PHP_MINFO(spl)
797 : */
798 : PHP_MINFO_FUNCTION(spl)
799 43 : {
800 : zval list;
801 : char *strg;
802 :
803 43 : php_info_print_table_start();
804 43 : php_info_print_table_header(2, "SPL support", "enabled");
805 :
806 43 : INIT_PZVAL(&list);
807 43 : array_init(&list);
808 43 : SPL_LIST_CLASSES(&list, 0, 1, ZEND_ACC_INTERFACE)
809 43 : strg = estrdup("");
810 43 : zend_hash_apply_with_argument(Z_ARRVAL_P(&list), (apply_func_arg_t)spl_build_class_list_string, &strg TSRMLS_CC);
811 43 : zval_dtor(&list);
812 43 : php_info_print_table_row(2, "Interfaces", strg + 2);
813 43 : efree(strg);
814 :
815 43 : INIT_PZVAL(&list);
816 43 : array_init(&list);
817 43 : SPL_LIST_CLASSES(&list, 0, -1, ZEND_ACC_INTERFACE)
818 43 : strg = estrdup("");
819 43 : zend_hash_apply_with_argument(Z_ARRVAL_P(&list), (apply_func_arg_t)spl_build_class_list_string, &strg TSRMLS_CC);
820 43 : zval_dtor(&list);
821 43 : php_info_print_table_row(2, "Classes", strg + 2);
822 43 : efree(strg);
823 :
824 43 : php_info_print_table_end();
825 43 : }
826 : /* }}} */
827 :
828 : /* {{{ arginfo */
829 : ZEND_BEGIN_ARG_INFO_EX(arginfo_iterator_to_array, 0, 0, 1)
830 : ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0)
831 : ZEND_ARG_INFO(0, use_keys)
832 : ZEND_END_ARG_INFO();
833 :
834 : ZEND_BEGIN_ARG_INFO(arginfo_iterator, 0)
835 : ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0)
836 : ZEND_END_ARG_INFO();
837 :
838 : ZEND_BEGIN_ARG_INFO_EX(arginfo_iterator_apply, 0, 0, 2)
839 : ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0)
840 : ZEND_ARG_INFO(0, function)
841 : ZEND_ARG_ARRAY_INFO(0, args, 1)
842 : ZEND_END_ARG_INFO();
843 :
844 : ZEND_BEGIN_ARG_INFO_EX(arginfo_class_parents, 0, 0, 1)
845 : ZEND_ARG_INFO(0, instance)
846 : ZEND_ARG_INFO(0, autoload)
847 : ZEND_END_ARG_INFO()
848 :
849 : ZEND_BEGIN_ARG_INFO_EX(arginfo_class_implements, 0, 0, 1)
850 : ZEND_ARG_INFO(0, what)
851 : ZEND_ARG_INFO(0, autoload)
852 : ZEND_END_ARG_INFO()
853 :
854 : ZEND_BEGIN_ARG_INFO(arginfo_spl_classes, 0)
855 : ZEND_END_ARG_INFO()
856 :
857 : ZEND_BEGIN_ARG_INFO(arginfo_spl_autoload_functions, 0)
858 : ZEND_END_ARG_INFO()
859 :
860 : ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_autoload, 0, 0, 1)
861 : ZEND_ARG_INFO(0, class_name)
862 : ZEND_ARG_INFO(0, file_extensions)
863 : ZEND_END_ARG_INFO()
864 :
865 : ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_autoload_extensions, 0, 0, 0)
866 : ZEND_ARG_INFO(0, file_extensions)
867 : ZEND_END_ARG_INFO()
868 :
869 : ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_autoload_call, 0, 0, 1)
870 : ZEND_ARG_INFO(0, class_name)
871 : ZEND_END_ARG_INFO()
872 :
873 : ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_autoload_register, 0, 0, 0)
874 : ZEND_ARG_INFO(0, autoload_function)
875 : ZEND_END_ARG_INFO()
876 :
877 : ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_autoload_unregister, 0, 0, 1)
878 : ZEND_ARG_INFO(0, autoload_function)
879 : ZEND_END_ARG_INFO()
880 :
881 : ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_object_hash, 0, 0, 1)
882 : ZEND_ARG_INFO(0, obj)
883 : ZEND_END_ARG_INFO()
884 : /* }}} */
885 :
886 : /* {{{ spl_functions
887 : */
888 : const zend_function_entry spl_functions[] = {
889 : PHP_FE(spl_classes, arginfo_spl_classes)
890 : PHP_FE(spl_autoload, arginfo_spl_autoload)
891 : PHP_FE(spl_autoload_extensions, arginfo_spl_autoload_extensions)
892 : PHP_FE(spl_autoload_register, arginfo_spl_autoload_register)
893 : PHP_FE(spl_autoload_unregister, arginfo_spl_autoload_unregister)
894 : PHP_FE(spl_autoload_functions, arginfo_spl_autoload_functions)
895 : PHP_FE(spl_autoload_call, arginfo_spl_autoload_call)
896 : PHP_FE(class_parents, arginfo_class_parents)
897 : PHP_FE(class_implements, arginfo_class_implements)
898 : PHP_FE(spl_object_hash, arginfo_spl_object_hash)
899 : #ifdef SPL_ITERATORS_H
900 : PHP_FE(iterator_to_array, arginfo_iterator_to_array)
901 : PHP_FE(iterator_count, arginfo_iterator)
902 : PHP_FE(iterator_apply, arginfo_iterator_apply)
903 : #endif /* SPL_ITERATORS_H */
904 : {NULL, NULL, NULL}
905 : };
906 : /* }}} */
907 :
908 : /* {{{ PHP_MINIT_FUNCTION(spl)
909 : */
910 : PHP_MINIT_FUNCTION(spl)
911 17007 : {
912 17007 : PHP_MINIT(spl_exceptions)(INIT_FUNC_ARGS_PASSTHRU);
913 17007 : PHP_MINIT(spl_iterators)(INIT_FUNC_ARGS_PASSTHRU);
914 17007 : PHP_MINIT(spl_array)(INIT_FUNC_ARGS_PASSTHRU);
915 17007 : PHP_MINIT(spl_directory)(INIT_FUNC_ARGS_PASSTHRU);
916 17007 : PHP_MINIT(spl_dllist)(INIT_FUNC_ARGS_PASSTHRU);
917 17007 : PHP_MINIT(spl_heap)(INIT_FUNC_ARGS_PASSTHRU);
918 17007 : PHP_MINIT(spl_fixedarray)(INIT_FUNC_ARGS_PASSTHRU);
919 17007 : PHP_MINIT(spl_observer)(INIT_FUNC_ARGS_PASSTHRU);
920 :
921 17007 : return SUCCESS;
922 : }
923 : /* }}} */
924 :
925 : PHP_RINIT_FUNCTION(spl) /* {{{ */
926 16993 : {
927 16993 : INIT_PZVAL(&SPL_G(autoload_extensions));
928 16993 : ZVAL_ASCII_STRINGL(&SPL_G(autoload_extensions), ".inc,.php", sizeof(".inc,.php")-1, 1);
929 16993 : SPL_G(autoload_functions) = NULL;
930 16993 : SPL_G(autoload_running) = 0;
931 16993 : SPL_G(autoload_running) = 0;
932 16993 : SPL_G(hash_mask_init) = 0;
933 16993 : return SUCCESS;
934 : } /* }}} */
935 :
936 : PHP_RSHUTDOWN_FUNCTION(spl) /* {{{ */
937 17025 : {
938 17025 : if (Z_TYPE(SPL_G(autoload_extensions)) != IS_NULL) {
939 17025 : zval_dtor(&SPL_G(autoload_extensions));
940 17025 : ZVAL_NULL(&SPL_G(autoload_extensions));
941 : }
942 17025 : if (SPL_G(autoload_functions)) {
943 20 : zend_hash_destroy(SPL_G(autoload_functions));
944 20 : FREE_HASHTABLE(SPL_G(autoload_functions));
945 20 : SPL_G(autoload_functions) = NULL;
946 : }
947 17025 : if (SPL_G(hash_mask_init)) {
948 6 : SPL_G(hash_mask_init) = 0;
949 : }
950 17025 : return SUCCESS;
951 : } /* }}} */
952 :
953 : /* {{{ spl_module_entry
954 : */
955 : zend_module_entry spl_module_entry = {
956 : STANDARD_MODULE_HEADER,
957 : "SPL",
958 : spl_functions,
959 : PHP_MINIT(spl),
960 : NULL,
961 : PHP_RINIT(spl),
962 : PHP_RSHUTDOWN(spl),
963 : PHP_MINFO(spl),
964 : "0.2",
965 : PHP_MODULE_GLOBALS(spl),
966 : PHP_GINIT(spl),
967 : NULL,
968 : NULL,
969 : STANDARD_MODULE_PROPERTIES_EX
970 : };
971 : /* }}} */
972 :
973 : /*
974 : * Local variables:
975 : * tab-width: 4
976 : * c-basic-offset: 4
977 : * End:
978 : * vim600: fdm=marker
979 : * vim: noet sw=4 ts=4
980 : */
|