php_spl.c 32 KB

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