zend_builtin_functions.c 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend Engine |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1998-2018 Zend Technologies Ltd. (http://www.zend.com) |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 2.00 of the Zend 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.zend.com/license/2_00.txt. |
  11. | If you did not receive a copy of the Zend license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@zend.com so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Andi Gutmans <andi@php.net> |
  16. | Zeev Suraski <zeev@php.net> |
  17. +----------------------------------------------------------------------+
  18. */
  19. #include "zend.h"
  20. #include "zend_API.h"
  21. #include "zend_gc.h"
  22. #include "zend_builtin_functions.h"
  23. #include "zend_constants.h"
  24. #include "zend_ini.h"
  25. #include "zend_exceptions.h"
  26. #include "zend_extensions.h"
  27. #include "zend_closures.h"
  28. #include "zend_generators.h"
  29. static ZEND_FUNCTION(zend_version);
  30. static ZEND_FUNCTION(func_num_args);
  31. static ZEND_FUNCTION(func_get_arg);
  32. static ZEND_FUNCTION(func_get_args);
  33. static ZEND_FUNCTION(strlen);
  34. static ZEND_FUNCTION(strcmp);
  35. static ZEND_FUNCTION(strncmp);
  36. static ZEND_FUNCTION(strcasecmp);
  37. static ZEND_FUNCTION(strncasecmp);
  38. static ZEND_FUNCTION(each);
  39. static ZEND_FUNCTION(error_reporting);
  40. static ZEND_FUNCTION(define);
  41. static ZEND_FUNCTION(defined);
  42. static ZEND_FUNCTION(get_class);
  43. static ZEND_FUNCTION(get_called_class);
  44. static ZEND_FUNCTION(get_parent_class);
  45. static ZEND_FUNCTION(method_exists);
  46. static ZEND_FUNCTION(property_exists);
  47. static ZEND_FUNCTION(class_exists);
  48. static ZEND_FUNCTION(interface_exists);
  49. static ZEND_FUNCTION(trait_exists);
  50. static ZEND_FUNCTION(function_exists);
  51. static ZEND_FUNCTION(class_alias);
  52. static ZEND_FUNCTION(get_included_files);
  53. static ZEND_FUNCTION(is_subclass_of);
  54. static ZEND_FUNCTION(is_a);
  55. static ZEND_FUNCTION(get_class_vars);
  56. static ZEND_FUNCTION(get_object_vars);
  57. static ZEND_FUNCTION(get_class_methods);
  58. static ZEND_FUNCTION(trigger_error);
  59. static ZEND_FUNCTION(set_error_handler);
  60. static ZEND_FUNCTION(restore_error_handler);
  61. static ZEND_FUNCTION(set_exception_handler);
  62. static ZEND_FUNCTION(restore_exception_handler);
  63. static ZEND_FUNCTION(get_declared_classes);
  64. static ZEND_FUNCTION(get_declared_traits);
  65. static ZEND_FUNCTION(get_declared_interfaces);
  66. static ZEND_FUNCTION(get_defined_functions);
  67. static ZEND_FUNCTION(get_defined_vars);
  68. static ZEND_FUNCTION(create_function);
  69. static ZEND_FUNCTION(get_resource_type);
  70. static ZEND_FUNCTION(get_resources);
  71. static ZEND_FUNCTION(get_loaded_extensions);
  72. static ZEND_FUNCTION(extension_loaded);
  73. static ZEND_FUNCTION(get_extension_funcs);
  74. static ZEND_FUNCTION(get_defined_constants);
  75. static ZEND_FUNCTION(debug_backtrace);
  76. static ZEND_FUNCTION(debug_print_backtrace);
  77. #if ZEND_DEBUG && defined(ZTS)
  78. static ZEND_FUNCTION(zend_thread_id);
  79. #endif
  80. static ZEND_FUNCTION(gc_mem_caches);
  81. static ZEND_FUNCTION(gc_collect_cycles);
  82. static ZEND_FUNCTION(gc_enabled);
  83. static ZEND_FUNCTION(gc_enable);
  84. static ZEND_FUNCTION(gc_disable);
  85. static ZEND_FUNCTION(gc_status);
  86. /* {{{ arginfo */
  87. ZEND_BEGIN_ARG_INFO(arginfo_zend__void, 0)
  88. ZEND_END_ARG_INFO()
  89. ZEND_BEGIN_ARG_INFO_EX(arginfo_func_get_arg, 0, 0, 1)
  90. ZEND_ARG_INFO(0, arg_num)
  91. ZEND_END_ARG_INFO()
  92. ZEND_BEGIN_ARG_INFO_EX(arginfo_strlen, 0, 0, 1)
  93. ZEND_ARG_INFO(0, str)
  94. ZEND_END_ARG_INFO()
  95. ZEND_BEGIN_ARG_INFO_EX(arginfo_strcmp, 0, 0, 2)
  96. ZEND_ARG_INFO(0, str1)
  97. ZEND_ARG_INFO(0, str2)
  98. ZEND_END_ARG_INFO()
  99. ZEND_BEGIN_ARG_INFO_EX(arginfo_strncmp, 0, 0, 3)
  100. ZEND_ARG_INFO(0, str1)
  101. ZEND_ARG_INFO(0, str2)
  102. ZEND_ARG_INFO(0, len)
  103. ZEND_END_ARG_INFO()
  104. ZEND_BEGIN_ARG_INFO_EX(arginfo_each, 0, 0, 1)
  105. ZEND_ARG_INFO(1, arr)
  106. ZEND_END_ARG_INFO()
  107. ZEND_BEGIN_ARG_INFO_EX(arginfo_error_reporting, 0, 0, 0)
  108. ZEND_ARG_INFO(0, new_error_level)
  109. ZEND_END_ARG_INFO()
  110. ZEND_BEGIN_ARG_INFO_EX(arginfo_define, 0, 0, 2)
  111. ZEND_ARG_INFO(0, constant_name)
  112. ZEND_ARG_INFO(0, value)
  113. ZEND_ARG_INFO(0, case_insensitive)
  114. ZEND_END_ARG_INFO()
  115. ZEND_BEGIN_ARG_INFO_EX(arginfo_defined, 0, 0, 1)
  116. ZEND_ARG_INFO(0, constant_name)
  117. ZEND_END_ARG_INFO()
  118. ZEND_BEGIN_ARG_INFO_EX(arginfo_get_class, 0, 0, 0)
  119. ZEND_ARG_INFO(0, object)
  120. ZEND_END_ARG_INFO()
  121. ZEND_BEGIN_ARG_INFO_EX(arginfo_is_subclass_of, 0, 0, 2)
  122. ZEND_ARG_INFO(0, object)
  123. ZEND_ARG_INFO(0, class_name)
  124. ZEND_ARG_INFO(0, allow_string)
  125. ZEND_END_ARG_INFO()
  126. ZEND_BEGIN_ARG_INFO_EX(arginfo_get_class_vars, 0, 0, 1)
  127. ZEND_ARG_INFO(0, class_name)
  128. ZEND_END_ARG_INFO()
  129. ZEND_BEGIN_ARG_INFO_EX(arginfo_get_object_vars, 0, 0, 1)
  130. ZEND_ARG_INFO(0, obj)
  131. ZEND_END_ARG_INFO()
  132. ZEND_BEGIN_ARG_INFO_EX(arginfo_get_class_methods, 0, 0, 1)
  133. ZEND_ARG_INFO(0, class)
  134. ZEND_END_ARG_INFO()
  135. ZEND_BEGIN_ARG_INFO_EX(arginfo_method_exists, 0, 0, 2)
  136. ZEND_ARG_INFO(0, object)
  137. ZEND_ARG_INFO(0, method)
  138. ZEND_END_ARG_INFO()
  139. ZEND_BEGIN_ARG_INFO_EX(arginfo_property_exists, 0, 0, 2)
  140. ZEND_ARG_INFO(0, object_or_class)
  141. ZEND_ARG_INFO(0, property_name)
  142. ZEND_END_ARG_INFO()
  143. ZEND_BEGIN_ARG_INFO_EX(arginfo_class_exists, 0, 0, 1)
  144. ZEND_ARG_INFO(0, classname)
  145. ZEND_ARG_INFO(0, autoload)
  146. ZEND_END_ARG_INFO()
  147. ZEND_BEGIN_ARG_INFO_EX(arginfo_trait_exists, 0, 0, 1)
  148. ZEND_ARG_INFO(0, traitname)
  149. ZEND_ARG_INFO(0, autoload)
  150. ZEND_END_ARG_INFO()
  151. ZEND_BEGIN_ARG_INFO_EX(arginfo_function_exists, 0, 0, 1)
  152. ZEND_ARG_INFO(0, function_name)
  153. ZEND_END_ARG_INFO()
  154. ZEND_BEGIN_ARG_INFO_EX(arginfo_class_alias, 0, 0, 2)
  155. ZEND_ARG_INFO(0, user_class_name)
  156. ZEND_ARG_INFO(0, alias_name)
  157. ZEND_ARG_INFO(0, autoload)
  158. ZEND_END_ARG_INFO()
  159. ZEND_BEGIN_ARG_INFO_EX(arginfo_trigger_error, 0, 0, 1)
  160. ZEND_ARG_INFO(0, message)
  161. ZEND_ARG_INFO(0, error_type)
  162. ZEND_END_ARG_INFO()
  163. ZEND_BEGIN_ARG_INFO_EX(arginfo_set_error_handler, 0, 0, 1)
  164. ZEND_ARG_INFO(0, error_handler)
  165. ZEND_ARG_INFO(0, error_types)
  166. ZEND_END_ARG_INFO()
  167. ZEND_BEGIN_ARG_INFO_EX(arginfo_set_exception_handler, 0, 0, 1)
  168. ZEND_ARG_INFO(0, exception_handler)
  169. ZEND_END_ARG_INFO()
  170. ZEND_BEGIN_ARG_INFO_EX(arginfo_get_defined_functions, 0, 0, 0)
  171. ZEND_ARG_INFO(0, exclude_disabled)
  172. ZEND_END_ARG_INFO()
  173. ZEND_BEGIN_ARG_INFO_EX(arginfo_create_function, 0, 0, 2)
  174. ZEND_ARG_INFO(0, args)
  175. ZEND_ARG_INFO(0, code)
  176. ZEND_END_ARG_INFO()
  177. ZEND_BEGIN_ARG_INFO_EX(arginfo_get_resource_type, 0, 0, 1)
  178. ZEND_ARG_INFO(0, res)
  179. ZEND_END_ARG_INFO()
  180. ZEND_BEGIN_ARG_INFO_EX(arginfo_get_resources, 0, 0, 0)
  181. ZEND_ARG_INFO(0, type)
  182. ZEND_END_ARG_INFO()
  183. ZEND_BEGIN_ARG_INFO_EX(arginfo_get_loaded_extensions, 0, 0, 0)
  184. ZEND_ARG_INFO(0, zend_extensions)
  185. ZEND_END_ARG_INFO()
  186. ZEND_BEGIN_ARG_INFO_EX(arginfo_get_defined_constants, 0, 0, 0)
  187. ZEND_ARG_INFO(0, categorize)
  188. ZEND_END_ARG_INFO()
  189. ZEND_BEGIN_ARG_INFO_EX(arginfo_debug_backtrace, 0, 0, 0)
  190. ZEND_ARG_INFO(0, options)
  191. ZEND_ARG_INFO(0, limit)
  192. ZEND_END_ARG_INFO()
  193. ZEND_BEGIN_ARG_INFO_EX(arginfo_debug_print_backtrace, 0, 0, 0)
  194. ZEND_ARG_INFO(0, options)
  195. ZEND_ARG_INFO(0, limit)
  196. ZEND_END_ARG_INFO()
  197. ZEND_BEGIN_ARG_INFO_EX(arginfo_extension_loaded, 0, 0, 1)
  198. ZEND_ARG_INFO(0, extension_name)
  199. ZEND_END_ARG_INFO()
  200. /* }}} */
  201. static const zend_function_entry builtin_functions[] = { /* {{{ */
  202. ZEND_FE(zend_version, arginfo_zend__void)
  203. ZEND_FE(func_num_args, arginfo_zend__void)
  204. ZEND_FE(func_get_arg, arginfo_func_get_arg)
  205. ZEND_FE(func_get_args, arginfo_zend__void)
  206. ZEND_FE(strlen, arginfo_strlen)
  207. ZEND_FE(strcmp, arginfo_strcmp)
  208. ZEND_FE(strncmp, arginfo_strncmp)
  209. ZEND_FE(strcasecmp, arginfo_strcmp)
  210. ZEND_FE(strncasecmp, arginfo_strncmp)
  211. ZEND_FE(each, arginfo_each)
  212. ZEND_FE(error_reporting, arginfo_error_reporting)
  213. ZEND_FE(define, arginfo_define)
  214. ZEND_FE(defined, arginfo_defined)
  215. ZEND_FE(get_class, arginfo_get_class)
  216. ZEND_FE(get_called_class, arginfo_zend__void)
  217. ZEND_FE(get_parent_class, arginfo_get_class)
  218. ZEND_FE(method_exists, arginfo_method_exists)
  219. ZEND_FE(property_exists, arginfo_property_exists)
  220. ZEND_FE(class_exists, arginfo_class_exists)
  221. ZEND_FE(interface_exists, arginfo_class_exists)
  222. ZEND_FE(trait_exists, arginfo_trait_exists)
  223. ZEND_FE(function_exists, arginfo_function_exists)
  224. ZEND_FE(class_alias, arginfo_class_alias)
  225. ZEND_FE(get_included_files, arginfo_zend__void)
  226. ZEND_FALIAS(get_required_files, get_included_files, arginfo_zend__void)
  227. ZEND_FE(is_subclass_of, arginfo_is_subclass_of)
  228. ZEND_FE(is_a, arginfo_is_subclass_of)
  229. ZEND_FE(get_class_vars, arginfo_get_class_vars)
  230. ZEND_FE(get_object_vars, arginfo_get_object_vars)
  231. ZEND_FE(get_class_methods, arginfo_get_class_methods)
  232. ZEND_FE(trigger_error, arginfo_trigger_error)
  233. ZEND_FALIAS(user_error, trigger_error, arginfo_trigger_error)
  234. ZEND_FE(set_error_handler, arginfo_set_error_handler)
  235. ZEND_FE(restore_error_handler, arginfo_zend__void)
  236. ZEND_FE(set_exception_handler, arginfo_set_exception_handler)
  237. ZEND_FE(restore_exception_handler, arginfo_zend__void)
  238. ZEND_FE(get_declared_classes, arginfo_zend__void)
  239. ZEND_FE(get_declared_traits, arginfo_zend__void)
  240. ZEND_FE(get_declared_interfaces, arginfo_zend__void)
  241. ZEND_FE(get_defined_functions, arginfo_get_defined_functions)
  242. ZEND_FE(get_defined_vars, arginfo_zend__void)
  243. ZEND_DEP_FE(create_function, arginfo_create_function)
  244. ZEND_FE(get_resource_type, arginfo_get_resource_type)
  245. ZEND_FE(get_resources, arginfo_get_resources)
  246. ZEND_FE(get_loaded_extensions, arginfo_get_loaded_extensions)
  247. ZEND_FE(extension_loaded, arginfo_extension_loaded)
  248. ZEND_FE(get_extension_funcs, arginfo_extension_loaded)
  249. ZEND_FE(get_defined_constants, arginfo_get_defined_constants)
  250. ZEND_FE(debug_backtrace, arginfo_debug_backtrace)
  251. ZEND_FE(debug_print_backtrace, arginfo_debug_print_backtrace)
  252. #if ZEND_DEBUG && defined(ZTS)
  253. ZEND_FE(zend_thread_id, NULL)
  254. #endif
  255. ZEND_FE(gc_mem_caches, arginfo_zend__void)
  256. ZEND_FE(gc_collect_cycles, arginfo_zend__void)
  257. ZEND_FE(gc_enabled, arginfo_zend__void)
  258. ZEND_FE(gc_enable, arginfo_zend__void)
  259. ZEND_FE(gc_disable, arginfo_zend__void)
  260. ZEND_FE(gc_status, arginfo_zend__void)
  261. ZEND_FE_END
  262. };
  263. /* }}} */
  264. ZEND_MINIT_FUNCTION(core) { /* {{{ */
  265. zend_class_entry class_entry;
  266. INIT_CLASS_ENTRY(class_entry, "stdClass", NULL);
  267. zend_standard_class_def = zend_register_internal_class(&class_entry);
  268. zend_register_default_classes();
  269. return SUCCESS;
  270. }
  271. /* }}} */
  272. zend_module_entry zend_builtin_module = { /* {{{ */
  273. STANDARD_MODULE_HEADER,
  274. "Core",
  275. builtin_functions,
  276. ZEND_MINIT(core),
  277. NULL,
  278. NULL,
  279. NULL,
  280. NULL,
  281. ZEND_VERSION,
  282. STANDARD_MODULE_PROPERTIES
  283. };
  284. /* }}} */
  285. int zend_startup_builtin_functions(void) /* {{{ */
  286. {
  287. zend_builtin_module.module_number = 0;
  288. zend_builtin_module.type = MODULE_PERSISTENT;
  289. return (EG(current_module) = zend_register_module_ex(&zend_builtin_module)) == NULL ? FAILURE : SUCCESS;
  290. }
  291. /* }}} */
  292. /* {{{ proto string zend_version(void)
  293. Get the version of the Zend Engine */
  294. ZEND_FUNCTION(zend_version)
  295. {
  296. if (zend_parse_parameters_none() == FAILURE) {
  297. return;
  298. }
  299. RETURN_STRINGL(ZEND_VERSION, sizeof(ZEND_VERSION)-1);
  300. }
  301. /* }}} */
  302. /* {{{ proto int gc_mem_caches(void)
  303. Reclaims memory used by MM caches.
  304. Returns number of freed bytes */
  305. ZEND_FUNCTION(gc_mem_caches)
  306. {
  307. if (zend_parse_parameters_none() == FAILURE) {
  308. return;
  309. }
  310. RETURN_LONG(zend_mm_gc(zend_mm_get_heap()));
  311. }
  312. /* }}} */
  313. /* {{{ proto int gc_collect_cycles(void)
  314. Forces collection of any existing garbage cycles.
  315. Returns number of freed zvals */
  316. ZEND_FUNCTION(gc_collect_cycles)
  317. {
  318. if (zend_parse_parameters_none() == FAILURE) {
  319. return;
  320. }
  321. RETURN_LONG(gc_collect_cycles());
  322. }
  323. /* }}} */
  324. /* {{{ proto void gc_enabled(void)
  325. Returns status of the circular reference collector */
  326. ZEND_FUNCTION(gc_enabled)
  327. {
  328. if (zend_parse_parameters_none() == FAILURE) {
  329. return;
  330. }
  331. RETURN_BOOL(gc_enabled());
  332. }
  333. /* }}} */
  334. /* {{{ proto void gc_enable(void)
  335. Activates the circular reference collector */
  336. ZEND_FUNCTION(gc_enable)
  337. {
  338. zend_string *key;
  339. if (zend_parse_parameters_none() == FAILURE) {
  340. return;
  341. }
  342. key = zend_string_init("zend.enable_gc", sizeof("zend.enable_gc")-1, 0);
  343. zend_alter_ini_entry_chars(key, "1", sizeof("1")-1, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME);
  344. zend_string_release_ex(key, 0);
  345. }
  346. /* }}} */
  347. /* {{{ proto void gc_disable(void)
  348. Deactivates the circular reference collector */
  349. ZEND_FUNCTION(gc_disable)
  350. {
  351. zend_string *key;
  352. if (zend_parse_parameters_none() == FAILURE) {
  353. return;
  354. }
  355. key = zend_string_init("zend.enable_gc", sizeof("zend.enable_gc")-1, 0);
  356. zend_alter_ini_entry_chars(key, "0", sizeof("0")-1, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME);
  357. zend_string_release_ex(key, 0);
  358. }
  359. /* }}} */
  360. /* {{{ proto array gc_status(void)
  361. Returns current GC statistics */
  362. ZEND_FUNCTION(gc_status)
  363. {
  364. zend_gc_status status;
  365. if (zend_parse_parameters_none() == FAILURE) {
  366. return;
  367. }
  368. zend_gc_get_status(&status);
  369. array_init_size(return_value, 3);
  370. add_assoc_long_ex(return_value, "runs", sizeof("runs")-1, (long)status.runs);
  371. add_assoc_long_ex(return_value, "collected", sizeof("collected")-1, (long)status.collected);
  372. add_assoc_long_ex(return_value, "threshold", sizeof("threshold")-1, (long)status.threshold);
  373. add_assoc_long_ex(return_value, "roots", sizeof("roots")-1, (long)status.num_roots);
  374. }
  375. /* }}} */
  376. /* {{{ proto int func_num_args(void)
  377. Get the number of arguments that were passed to the function */
  378. ZEND_FUNCTION(func_num_args)
  379. {
  380. zend_execute_data *ex = EX(prev_execute_data);
  381. if (zend_parse_parameters_none() == FAILURE) {
  382. return;
  383. }
  384. if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
  385. zend_error(E_WARNING, "func_num_args(): Called from the global scope - no function context");
  386. RETURN_LONG(-1);
  387. }
  388. if (zend_forbid_dynamic_call("func_num_args()") == FAILURE) {
  389. RETURN_LONG(-1);
  390. }
  391. RETURN_LONG(ZEND_CALL_NUM_ARGS(ex));
  392. }
  393. /* }}} */
  394. /* {{{ proto mixed func_get_arg(int arg_num)
  395. Get the $arg_num'th argument that was passed to the function */
  396. ZEND_FUNCTION(func_get_arg)
  397. {
  398. uint32_t arg_count, first_extra_arg;
  399. zval *arg;
  400. zend_long requested_offset;
  401. zend_execute_data *ex;
  402. if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &requested_offset) == FAILURE) {
  403. return;
  404. }
  405. if (requested_offset < 0) {
  406. zend_error(E_WARNING, "func_get_arg(): The argument number should be >= 0");
  407. RETURN_FALSE;
  408. }
  409. ex = EX(prev_execute_data);
  410. if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
  411. zend_error(E_WARNING, "func_get_arg(): Called from the global scope - no function context");
  412. RETURN_FALSE;
  413. }
  414. if (zend_forbid_dynamic_call("func_get_arg()") == FAILURE) {
  415. RETURN_FALSE;
  416. }
  417. arg_count = ZEND_CALL_NUM_ARGS(ex);
  418. if ((zend_ulong)requested_offset >= arg_count) {
  419. zend_error(E_WARNING, "func_get_arg(): Argument " ZEND_LONG_FMT " not passed to function", requested_offset);
  420. RETURN_FALSE;
  421. }
  422. first_extra_arg = ex->func->op_array.num_args;
  423. if ((zend_ulong)requested_offset >= first_extra_arg && (ZEND_CALL_NUM_ARGS(ex) > first_extra_arg)) {
  424. arg = ZEND_CALL_VAR_NUM(ex, ex->func->op_array.last_var + ex->func->op_array.T) + (requested_offset - first_extra_arg);
  425. } else {
  426. arg = ZEND_CALL_ARG(ex, requested_offset + 1);
  427. }
  428. if (EXPECTED(!Z_ISUNDEF_P(arg))) {
  429. ZVAL_COPY_DEREF(return_value, arg);
  430. }
  431. }
  432. /* }}} */
  433. /* {{{ proto array func_get_args()
  434. Get an array of the arguments that were passed to the function */
  435. ZEND_FUNCTION(func_get_args)
  436. {
  437. zval *p, *q;
  438. uint32_t arg_count, first_extra_arg;
  439. uint32_t i;
  440. zend_execute_data *ex = EX(prev_execute_data);
  441. if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
  442. zend_error(E_WARNING, "func_get_args(): Called from the global scope - no function context");
  443. RETURN_FALSE;
  444. }
  445. if (zend_forbid_dynamic_call("func_get_args()") == FAILURE) {
  446. RETURN_FALSE;
  447. }
  448. arg_count = ZEND_CALL_NUM_ARGS(ex);
  449. if (arg_count) {
  450. array_init_size(return_value, arg_count);
  451. first_extra_arg = ex->func->op_array.num_args;
  452. zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
  453. ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) {
  454. i = 0;
  455. p = ZEND_CALL_ARG(ex, 1);
  456. if (arg_count > first_extra_arg) {
  457. while (i < first_extra_arg) {
  458. q = p;
  459. if (EXPECTED(Z_TYPE_INFO_P(q) != IS_UNDEF)) {
  460. ZVAL_DEREF(q);
  461. if (Z_OPT_REFCOUNTED_P(q)) {
  462. Z_ADDREF_P(q);
  463. }
  464. } else {
  465. q = &EG(uninitialized_zval);
  466. }
  467. ZEND_HASH_FILL_ADD(q);
  468. p++;
  469. i++;
  470. }
  471. p = ZEND_CALL_VAR_NUM(ex, ex->func->op_array.last_var + ex->func->op_array.T);
  472. }
  473. while (i < arg_count) {
  474. q = p;
  475. if (EXPECTED(Z_TYPE_INFO_P(q) != IS_UNDEF)) {
  476. ZVAL_DEREF(q);
  477. if (Z_OPT_REFCOUNTED_P(q)) {
  478. Z_ADDREF_P(q);
  479. }
  480. } else {
  481. q = &EG(uninitialized_zval);
  482. }
  483. ZEND_HASH_FILL_ADD(q);
  484. p++;
  485. i++;
  486. }
  487. } ZEND_HASH_FILL_END();
  488. Z_ARRVAL_P(return_value)->nNumOfElements = arg_count;
  489. } else {
  490. ZVAL_EMPTY_ARRAY(return_value);
  491. }
  492. }
  493. /* }}} */
  494. /* {{{ proto int strlen(string str)
  495. Get string length
  496. Warning: This function is special-cased by zend_compile.c and so is usually bypassed */
  497. ZEND_FUNCTION(strlen)
  498. {
  499. zend_string *s;
  500. ZEND_PARSE_PARAMETERS_START(1, 1)
  501. Z_PARAM_STR(s)
  502. ZEND_PARSE_PARAMETERS_END();
  503. RETVAL_LONG(ZSTR_LEN(s));
  504. }
  505. /* }}} */
  506. /* {{{ proto int strcmp(string str1, string str2)
  507. Binary safe string comparison */
  508. ZEND_FUNCTION(strcmp)
  509. {
  510. zend_string *s1, *s2;
  511. ZEND_PARSE_PARAMETERS_START(2, 2)
  512. Z_PARAM_STR(s1)
  513. Z_PARAM_STR(s2)
  514. ZEND_PARSE_PARAMETERS_END();
  515. RETURN_LONG(zend_binary_strcmp(ZSTR_VAL(s1), ZSTR_LEN(s1), ZSTR_VAL(s2), ZSTR_LEN(s2)));
  516. }
  517. /* }}} */
  518. /* {{{ proto int strncmp(string str1, string str2, int len)
  519. Binary safe string comparison */
  520. ZEND_FUNCTION(strncmp)
  521. {
  522. zend_string *s1, *s2;
  523. zend_long len;
  524. ZEND_PARSE_PARAMETERS_START(3, 3)
  525. Z_PARAM_STR(s1)
  526. Z_PARAM_STR(s2)
  527. Z_PARAM_LONG(len)
  528. ZEND_PARSE_PARAMETERS_END();
  529. if (len < 0) {
  530. zend_error(E_WARNING, "Length must be greater than or equal to 0");
  531. RETURN_FALSE;
  532. }
  533. RETURN_LONG(zend_binary_strncmp(ZSTR_VAL(s1), ZSTR_LEN(s1), ZSTR_VAL(s2), ZSTR_LEN(s2), len));
  534. }
  535. /* }}} */
  536. /* {{{ proto int strcasecmp(string str1, string str2)
  537. Binary safe case-insensitive string comparison */
  538. ZEND_FUNCTION(strcasecmp)
  539. {
  540. zend_string *s1, *s2;
  541. ZEND_PARSE_PARAMETERS_START(2, 2)
  542. Z_PARAM_STR(s1)
  543. Z_PARAM_STR(s2)
  544. ZEND_PARSE_PARAMETERS_END();
  545. RETURN_LONG(zend_binary_strcasecmp(ZSTR_VAL(s1), ZSTR_LEN(s1), ZSTR_VAL(s2), ZSTR_LEN(s2)));
  546. }
  547. /* }}} */
  548. /* {{{ proto int strncasecmp(string str1, string str2, int len)
  549. Binary safe string comparison */
  550. ZEND_FUNCTION(strncasecmp)
  551. {
  552. zend_string *s1, *s2;
  553. zend_long len;
  554. ZEND_PARSE_PARAMETERS_START(3, 3)
  555. Z_PARAM_STR(s1)
  556. Z_PARAM_STR(s2)
  557. Z_PARAM_LONG(len)
  558. ZEND_PARSE_PARAMETERS_END();
  559. if (len < 0) {
  560. zend_error(E_WARNING, "Length must be greater than or equal to 0");
  561. RETURN_FALSE;
  562. }
  563. RETURN_LONG(zend_binary_strncasecmp(ZSTR_VAL(s1), ZSTR_LEN(s1), ZSTR_VAL(s2), ZSTR_LEN(s2), len));
  564. }
  565. /* }}} */
  566. /* {{{ proto mixed each(array &arr)
  567. Return the currently pointed key..value pair in the passed array, and advance the pointer to the next element, or false if there is no element at this place */
  568. ZEND_FUNCTION(each)
  569. {
  570. zval *array, *entry, tmp;
  571. zend_ulong num_key;
  572. HashTable *target_hash;
  573. zend_string *key;
  574. if (zend_parse_parameters(ZEND_NUM_ARGS(), "z/", &array) == FAILURE) {
  575. return;
  576. }
  577. if (!EG(each_deprecation_thrown)) {
  578. zend_error(E_DEPRECATED, "The each() function is deprecated. This message will be suppressed on further calls");
  579. EG(each_deprecation_thrown) = 1;
  580. }
  581. target_hash = HASH_OF(array);
  582. if (!target_hash) {
  583. zend_error(E_WARNING,"Variable passed to each() is not an array or object");
  584. return;
  585. }
  586. while (1) {
  587. entry = zend_hash_get_current_data(target_hash);
  588. if (!entry) {
  589. RETURN_FALSE;
  590. } else if (Z_TYPE_P(entry) == IS_INDIRECT) {
  591. entry = Z_INDIRECT_P(entry);
  592. if (Z_TYPE_P(entry) == IS_UNDEF) {
  593. zend_hash_move_forward(target_hash);
  594. continue;
  595. }
  596. }
  597. break;
  598. }
  599. array_init_size(return_value, 4);
  600. zend_hash_real_init_mixed(Z_ARRVAL_P(return_value));
  601. /* add value elements */
  602. ZVAL_DEREF(entry);
  603. if (Z_REFCOUNTED_P(entry)) {
  604. GC_ADDREF_EX(Z_COUNTED_P(entry), 2);
  605. }
  606. zend_hash_index_add_new(Z_ARRVAL_P(return_value), 1, entry);
  607. zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_VALUE), entry);
  608. /* add the key elements */
  609. if (zend_hash_get_current_key(target_hash, &key, &num_key) == HASH_KEY_IS_STRING) {
  610. ZVAL_STR_COPY(&tmp, key);
  611. Z_TRY_ADDREF(tmp);
  612. } else {
  613. ZVAL_LONG(&tmp, num_key);
  614. }
  615. zend_hash_index_add_new(Z_ARRVAL_P(return_value), 0, &tmp);
  616. zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_KEY), &tmp);
  617. zend_hash_move_forward(target_hash);
  618. }
  619. /* }}} */
  620. /* {{{ proto int error_reporting([int new_error_level])
  621. Return the current error_reporting level, and if an argument was passed - change to the new level */
  622. ZEND_FUNCTION(error_reporting)
  623. {
  624. zval *err = NULL;
  625. int old_error_reporting;
  626. ZEND_PARSE_PARAMETERS_START(0, 1)
  627. Z_PARAM_OPTIONAL
  628. Z_PARAM_ZVAL(err)
  629. ZEND_PARSE_PARAMETERS_END();
  630. old_error_reporting = EG(error_reporting);
  631. if (ZEND_NUM_ARGS() != 0) {
  632. zend_string *new_val = zval_get_string(err);
  633. do {
  634. zend_ini_entry *p = EG(error_reporting_ini_entry);
  635. if (!p) {
  636. zval *zv = zend_hash_find_ex(EG(ini_directives), ZSTR_KNOWN(ZEND_STR_ERROR_REPORTING), 1);
  637. if (zv) {
  638. p = EG(error_reporting_ini_entry) = (zend_ini_entry*)Z_PTR_P(zv);
  639. } else {
  640. break;
  641. }
  642. }
  643. if (!p->modified) {
  644. if (!EG(modified_ini_directives)) {
  645. ALLOC_HASHTABLE(EG(modified_ini_directives));
  646. zend_hash_init(EG(modified_ini_directives), 8, NULL, NULL, 0);
  647. }
  648. if (EXPECTED(zend_hash_add_ptr(EG(modified_ini_directives), ZSTR_KNOWN(ZEND_STR_ERROR_REPORTING), p) != NULL)) {
  649. p->orig_value = p->value;
  650. p->orig_modifiable = p->modifiable;
  651. p->modified = 1;
  652. }
  653. } else if (p->orig_value != p->value) {
  654. zend_string_release_ex(p->value, 0);
  655. }
  656. p->value = new_val;
  657. if (Z_TYPE_P(err) == IS_LONG) {
  658. EG(error_reporting) = Z_LVAL_P(err);
  659. } else {
  660. EG(error_reporting) = atoi(ZSTR_VAL(p->value));
  661. }
  662. } while (0);
  663. }
  664. RETVAL_LONG(old_error_reporting);
  665. }
  666. /* }}} */
  667. static int validate_constant_array(HashTable *ht) /* {{{ */
  668. {
  669. int ret = 1;
  670. zval *val;
  671. GC_PROTECT_RECURSION(ht);
  672. ZEND_HASH_FOREACH_VAL_IND(ht, val) {
  673. ZVAL_DEREF(val);
  674. if (Z_REFCOUNTED_P(val)) {
  675. if (Z_TYPE_P(val) == IS_ARRAY) {
  676. if (Z_REFCOUNTED_P(val)) {
  677. if (Z_IS_RECURSIVE_P(val)) {
  678. zend_error(E_WARNING, "Constants cannot be recursive arrays");
  679. ret = 0;
  680. break;
  681. } else if (!validate_constant_array(Z_ARRVAL_P(val))) {
  682. ret = 0;
  683. break;
  684. }
  685. }
  686. } else if (Z_TYPE_P(val) != IS_STRING && Z_TYPE_P(val) != IS_RESOURCE) {
  687. zend_error(E_WARNING, "Constants may only evaluate to scalar values, arrays or resources");
  688. ret = 0;
  689. break;
  690. }
  691. }
  692. } ZEND_HASH_FOREACH_END();
  693. GC_UNPROTECT_RECURSION(ht);
  694. return ret;
  695. }
  696. /* }}} */
  697. static void copy_constant_array(zval *dst, zval *src) /* {{{ */
  698. {
  699. zend_string *key;
  700. zend_ulong idx;
  701. zval *new_val, *val;
  702. array_init_size(dst, zend_hash_num_elements(Z_ARRVAL_P(src)));
  703. ZEND_HASH_FOREACH_KEY_VAL_IND(Z_ARRVAL_P(src), idx, key, val) {
  704. /* constant arrays can't contain references */
  705. ZVAL_DEREF(val);
  706. if (key) {
  707. new_val = zend_hash_add_new(Z_ARRVAL_P(dst), key, val);
  708. } else {
  709. new_val = zend_hash_index_add_new(Z_ARRVAL_P(dst), idx, val);
  710. }
  711. if (Z_TYPE_P(val) == IS_ARRAY) {
  712. if (Z_REFCOUNTED_P(val)) {
  713. copy_constant_array(new_val, val);
  714. }
  715. } else {
  716. Z_TRY_ADDREF_P(val);
  717. }
  718. } ZEND_HASH_FOREACH_END();
  719. }
  720. /* }}} */
  721. /* {{{ proto bool define(string constant_name, mixed value[, bool case_insensitive])
  722. Define a new constant */
  723. ZEND_FUNCTION(define)
  724. {
  725. zend_string *name;
  726. zval *val, val_free;
  727. zend_bool non_cs = 0;
  728. int case_sensitive = CONST_CS;
  729. zend_constant c;
  730. ZEND_PARSE_PARAMETERS_START(2, 3)
  731. Z_PARAM_STR(name)
  732. Z_PARAM_ZVAL(val)
  733. Z_PARAM_OPTIONAL
  734. Z_PARAM_BOOL(non_cs)
  735. ZEND_PARSE_PARAMETERS_END();
  736. if (non_cs) {
  737. case_sensitive = 0;
  738. }
  739. if (zend_memnstr(ZSTR_VAL(name), "::", sizeof("::") - 1, ZSTR_VAL(name) + ZSTR_LEN(name))) {
  740. zend_error(E_WARNING, "Class constants cannot be defined or redefined");
  741. RETURN_FALSE;
  742. }
  743. ZVAL_UNDEF(&val_free);
  744. repeat:
  745. switch (Z_TYPE_P(val)) {
  746. case IS_LONG:
  747. case IS_DOUBLE:
  748. case IS_STRING:
  749. case IS_FALSE:
  750. case IS_TRUE:
  751. case IS_NULL:
  752. case IS_RESOURCE:
  753. break;
  754. case IS_ARRAY:
  755. if (Z_REFCOUNTED_P(val)) {
  756. if (!validate_constant_array(Z_ARRVAL_P(val))) {
  757. RETURN_FALSE;
  758. } else {
  759. copy_constant_array(&c.value, val);
  760. goto register_constant;
  761. }
  762. }
  763. break;
  764. case IS_OBJECT:
  765. if (Z_TYPE(val_free) == IS_UNDEF) {
  766. if (Z_OBJ_HT_P(val)->get) {
  767. val = Z_OBJ_HT_P(val)->get(val, &val_free);
  768. goto repeat;
  769. } else if (Z_OBJ_HT_P(val)->cast_object) {
  770. if (Z_OBJ_HT_P(val)->cast_object(val, &val_free, IS_STRING) == SUCCESS) {
  771. val = &val_free;
  772. break;
  773. }
  774. }
  775. }
  776. /* no break */
  777. default:
  778. zend_error(E_WARNING, "Constants may only evaluate to scalar values, arrays or resources");
  779. zval_ptr_dtor(&val_free);
  780. RETURN_FALSE;
  781. }
  782. ZVAL_COPY(&c.value, val);
  783. zval_ptr_dtor(&val_free);
  784. register_constant:
  785. if (non_cs) {
  786. zend_error(E_DEPRECATED,
  787. "define(): Declaration of case-insensitive constants is deprecated");
  788. }
  789. /* non persistent */
  790. ZEND_CONSTANT_SET_FLAGS(&c, case_sensitive, PHP_USER_CONSTANT);
  791. c.name = zend_string_copy(name);
  792. if (zend_register_constant(&c) == SUCCESS) {
  793. RETURN_TRUE;
  794. } else {
  795. RETURN_FALSE;
  796. }
  797. }
  798. /* }}} */
  799. /* {{{ proto bool defined(string constant_name)
  800. Check whether a constant exists
  801. Warning: This function is special-cased by zend_compile.c and so is usually bypassed */
  802. ZEND_FUNCTION(defined)
  803. {
  804. zend_string *name;
  805. ZEND_PARSE_PARAMETERS_START(1, 1)
  806. Z_PARAM_STR(name)
  807. ZEND_PARSE_PARAMETERS_END();
  808. if (zend_get_constant_ex(name, zend_get_executed_scope(), ZEND_FETCH_CLASS_SILENT | ZEND_GET_CONSTANT_NO_DEPRECATION_CHECK)) {
  809. RETURN_TRUE;
  810. } else {
  811. RETURN_FALSE;
  812. }
  813. }
  814. /* }}} */
  815. /* {{{ proto string get_class([object object])
  816. Retrieves the class name */
  817. ZEND_FUNCTION(get_class)
  818. {
  819. zval *obj = NULL;
  820. if (zend_parse_parameters(ZEND_NUM_ARGS(), "|o", &obj) == FAILURE) {
  821. RETURN_FALSE;
  822. }
  823. if (!obj) {
  824. zend_class_entry *scope = zend_get_executed_scope();
  825. if (scope) {
  826. RETURN_STR_COPY(scope->name);
  827. } else {
  828. zend_error(E_WARNING, "get_class() called without object from outside a class");
  829. RETURN_FALSE;
  830. }
  831. }
  832. RETURN_STR_COPY(Z_OBJCE_P(obj)->name);
  833. }
  834. /* }}} */
  835. /* {{{ proto string get_called_class()
  836. Retrieves the "Late Static Binding" class name */
  837. ZEND_FUNCTION(get_called_class)
  838. {
  839. zend_class_entry *called_scope;
  840. if (zend_parse_parameters_none() == FAILURE) {
  841. return;
  842. }
  843. called_scope = zend_get_called_scope(execute_data);
  844. if (called_scope) {
  845. RETURN_STR_COPY(called_scope->name);
  846. } else {
  847. zend_class_entry *scope = zend_get_executed_scope();
  848. if (!scope) {
  849. zend_error(E_WARNING, "get_called_class() called from outside a class");
  850. }
  851. }
  852. RETURN_FALSE;
  853. }
  854. /* }}} */
  855. /* {{{ proto mixed get_parent_class([mixed object])
  856. Retrieves the parent class name for object or class or current scope or false if not in a scope. */
  857. ZEND_FUNCTION(get_parent_class)
  858. {
  859. zval *arg;
  860. zend_class_entry *ce = NULL;
  861. if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z", &arg) == FAILURE) {
  862. return;
  863. }
  864. if (!ZEND_NUM_ARGS()) {
  865. ce = zend_get_executed_scope();
  866. if (ce && ce->parent) {
  867. RETURN_STR_COPY(ce->parent->name);
  868. } else {
  869. RETURN_FALSE;
  870. }
  871. }
  872. if (Z_TYPE_P(arg) == IS_OBJECT) {
  873. ce = Z_OBJ_P(arg)->ce;
  874. } else if (Z_TYPE_P(arg) == IS_STRING) {
  875. ce = zend_lookup_class(Z_STR_P(arg));
  876. }
  877. if (ce && ce->parent) {
  878. RETURN_STR_COPY(ce->parent->name);
  879. } else {
  880. RETURN_FALSE;
  881. }
  882. }
  883. /* }}} */
  884. static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass) /* {{{ */
  885. {
  886. zval *obj;
  887. zend_string *class_name;
  888. zend_class_entry *instance_ce;
  889. zend_class_entry *ce;
  890. zend_bool allow_string = only_subclass;
  891. zend_bool retval;
  892. ZEND_PARSE_PARAMETERS_START(2, 3)
  893. Z_PARAM_ZVAL(obj)
  894. Z_PARAM_STR(class_name)
  895. Z_PARAM_OPTIONAL
  896. Z_PARAM_BOOL(allow_string)
  897. ZEND_PARSE_PARAMETERS_END();
  898. /*
  899. * allow_string - is_a default is no, is_subclass_of is yes.
  900. * if it's allowed, then the autoloader will be called if the class does not exist.
  901. * default behaviour is different, as 'is_a' used to be used to test mixed return values
  902. * and there is no easy way to deprecate this.
  903. */
  904. if (allow_string && Z_TYPE_P(obj) == IS_STRING) {
  905. instance_ce = zend_lookup_class(Z_STR_P(obj));
  906. if (!instance_ce) {
  907. RETURN_FALSE;
  908. }
  909. } else if (Z_TYPE_P(obj) == IS_OBJECT) {
  910. instance_ce = Z_OBJCE_P(obj);
  911. } else {
  912. RETURN_FALSE;
  913. }
  914. if (!only_subclass && EXPECTED(zend_string_equals(instance_ce->name, class_name))) {
  915. retval = 1;
  916. } else {
  917. ce = zend_lookup_class_ex(class_name, NULL, 0);
  918. if (!ce) {
  919. retval = 0;
  920. } else {
  921. if (only_subclass && instance_ce == ce) {
  922. retval = 0;
  923. } else {
  924. retval = instanceof_function(instance_ce, ce);
  925. }
  926. }
  927. }
  928. RETURN_BOOL(retval);
  929. }
  930. /* }}} */
  931. /* {{{ proto bool is_subclass_of(mixed object_or_string, string class_name [, bool allow_string])
  932. Returns true if the object has this class as one of its parents */
  933. ZEND_FUNCTION(is_subclass_of)
  934. {
  935. is_a_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
  936. }
  937. /* }}} */
  938. /* {{{ proto bool is_a(mixed object_or_string, string class_name [, bool allow_string])
  939. Returns true if the first argument is an object and is this class or has this class as one of its parents, */
  940. ZEND_FUNCTION(is_a)
  941. {
  942. is_a_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
  943. }
  944. /* }}} */
  945. /* {{{ add_class_vars */
  946. static void add_class_vars(zend_class_entry *scope, zend_class_entry *ce, int statics, zval *return_value)
  947. {
  948. zend_property_info *prop_info;
  949. zval *prop, prop_copy;
  950. zend_string *key;
  951. ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) {
  952. if (((prop_info->flags & ZEND_ACC_SHADOW) &&
  953. prop_info->ce != scope) ||
  954. ((prop_info->flags & ZEND_ACC_PROTECTED) &&
  955. !zend_check_protected(prop_info->ce, scope)) ||
  956. ((prop_info->flags & ZEND_ACC_PRIVATE) &&
  957. ce != scope &&
  958. prop_info->ce != scope)) {
  959. continue;
  960. }
  961. prop = NULL;
  962. if (statics && (prop_info->flags & ZEND_ACC_STATIC) != 0) {
  963. prop = &ce->default_static_members_table[prop_info->offset];
  964. ZVAL_DEINDIRECT(prop);
  965. } else if (!statics && (prop_info->flags & ZEND_ACC_STATIC) == 0) {
  966. prop = &ce->default_properties_table[OBJ_PROP_TO_NUM(prop_info->offset)];
  967. }
  968. if (!prop || Z_TYPE_P(prop) == IS_UNDEF) {
  969. continue;
  970. }
  971. /* copy: enforce read only access */
  972. ZVAL_DEREF(prop);
  973. ZVAL_COPY_OR_DUP(&prop_copy, prop);
  974. prop = &prop_copy;
  975. /* this is necessary to make it able to work with default array
  976. * properties, returned to user */
  977. if (Z_OPT_TYPE_P(prop) == IS_CONSTANT_AST) {
  978. if (UNEXPECTED(zval_update_constant_ex(prop, NULL) != SUCCESS)) {
  979. return;
  980. }
  981. }
  982. zend_hash_add_new(Z_ARRVAL_P(return_value), key, prop);
  983. } ZEND_HASH_FOREACH_END();
  984. }
  985. /* }}} */
  986. /* {{{ proto array get_class_vars(string class_name)
  987. Returns an array of default properties of the class. */
  988. ZEND_FUNCTION(get_class_vars)
  989. {
  990. zend_string *class_name;
  991. zend_class_entry *ce, *scope;
  992. if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &class_name) == FAILURE) {
  993. return;
  994. }
  995. ce = zend_lookup_class(class_name);
  996. if (!ce) {
  997. RETURN_FALSE;
  998. } else {
  999. array_init(return_value);
  1000. if (UNEXPECTED(!(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED))) {
  1001. if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) {
  1002. return;
  1003. }
  1004. }
  1005. scope = zend_get_executed_scope();
  1006. add_class_vars(scope, ce, 0, return_value);
  1007. add_class_vars(scope, ce, 1, return_value);
  1008. }
  1009. }
  1010. /* }}} */
  1011. /* {{{ proto array get_object_vars(object obj)
  1012. Returns an array of object properties */
  1013. ZEND_FUNCTION(get_object_vars)
  1014. {
  1015. zval *obj;
  1016. zval *value;
  1017. HashTable *properties;
  1018. zend_string *key;
  1019. zend_object *zobj;
  1020. zend_ulong num_key;
  1021. ZEND_PARSE_PARAMETERS_START(1, 1)
  1022. Z_PARAM_OBJECT(obj)
  1023. ZEND_PARSE_PARAMETERS_END();
  1024. if (Z_OBJ_HT_P(obj)->get_properties == NULL) {
  1025. RETURN_FALSE;
  1026. }
  1027. properties = Z_OBJ_HT_P(obj)->get_properties(obj);
  1028. if (properties == NULL) {
  1029. RETURN_FALSE;
  1030. }
  1031. zobj = Z_OBJ_P(obj);
  1032. if (!zobj->ce->default_properties_count && properties == zobj->properties && !GC_IS_RECURSIVE(properties)) {
  1033. /* fast copy */
  1034. if (EXPECTED(zobj->handlers == &std_object_handlers)) {
  1035. RETURN_ARR(zend_proptable_to_symtable(properties, 0));
  1036. }
  1037. RETURN_ARR(zend_proptable_to_symtable(properties, 1));
  1038. } else {
  1039. array_init_size(return_value, zend_hash_num_elements(properties));
  1040. ZEND_HASH_FOREACH_KEY_VAL(properties, num_key, key, value) {
  1041. zend_bool unmangle = 0;
  1042. if (Z_TYPE_P(value) == IS_INDIRECT) {
  1043. value = Z_INDIRECT_P(value);
  1044. if (UNEXPECTED(Z_ISUNDEF_P(value))) {
  1045. continue;
  1046. }
  1047. ZEND_ASSERT(key);
  1048. if (zend_check_property_access(zobj, key) == FAILURE) {
  1049. continue;
  1050. }
  1051. unmangle = 1;
  1052. }
  1053. if (Z_ISREF_P(value) && Z_REFCOUNT_P(value) == 1) {
  1054. value = Z_REFVAL_P(value);
  1055. }
  1056. Z_TRY_ADDREF_P(value);
  1057. if (UNEXPECTED(!key)) {
  1058. /* This case is only possible due to loopholes, e.g. ArrayObject */
  1059. zend_hash_index_add(Z_ARRVAL_P(return_value), num_key, value);
  1060. } else if (unmangle && ZSTR_VAL(key)[0] == 0) {
  1061. const char *prop_name, *class_name;
  1062. size_t prop_len;
  1063. zend_unmangle_property_name_ex(key, &class_name, &prop_name, &prop_len);
  1064. /* We assume here that a mangled property name is never
  1065. * numeric. This is probably a safe assumption, but
  1066. * theoretically someone might write an extension with
  1067. * private, numeric properties. Well, too bad.
  1068. */
  1069. zend_hash_str_add_new(Z_ARRVAL_P(return_value), prop_name, prop_len, value);
  1070. } else {
  1071. zend_symtable_add_new(Z_ARRVAL_P(return_value), key, value);
  1072. }
  1073. } ZEND_HASH_FOREACH_END();
  1074. }
  1075. }
  1076. /* }}} */
  1077. static int same_name(zend_string *key, zend_string *name) /* {{{ */
  1078. {
  1079. zend_string *lcname;
  1080. int ret;
  1081. if (key == name) {
  1082. return 1;
  1083. }
  1084. if (ZSTR_LEN(key) != ZSTR_LEN(name)) {
  1085. return 0;
  1086. }
  1087. lcname = zend_string_tolower(name);
  1088. ret = memcmp(ZSTR_VAL(lcname), ZSTR_VAL(key), ZSTR_LEN(key)) == 0;
  1089. zend_string_release_ex(lcname, 0);
  1090. return ret;
  1091. }
  1092. /* }}} */
  1093. /* {{{ proto array get_class_methods(mixed class)
  1094. Returns an array of method names for class or class instance. */
  1095. ZEND_FUNCTION(get_class_methods)
  1096. {
  1097. zval *klass;
  1098. zval method_name;
  1099. zend_class_entry *ce = NULL;
  1100. zend_class_entry *scope;
  1101. zend_function *mptr;
  1102. zend_string *key;
  1103. if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &klass) == FAILURE) {
  1104. return;
  1105. }
  1106. if (Z_TYPE_P(klass) == IS_OBJECT) {
  1107. ce = Z_OBJCE_P(klass);
  1108. } else if (Z_TYPE_P(klass) == IS_STRING) {
  1109. ce = zend_lookup_class(Z_STR_P(klass));
  1110. }
  1111. if (!ce) {
  1112. RETURN_NULL();
  1113. }
  1114. array_init(return_value);
  1115. scope = zend_get_executed_scope();
  1116. ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->function_table, key, mptr) {
  1117. if ((mptr->common.fn_flags & ZEND_ACC_PUBLIC)
  1118. || (scope &&
  1119. (((mptr->common.fn_flags & ZEND_ACC_PROTECTED) &&
  1120. zend_check_protected(mptr->common.scope, scope))
  1121. || ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) &&
  1122. scope == mptr->common.scope)))) {
  1123. size_t len = ZSTR_LEN(mptr->common.function_name);
  1124. /* Do not display old-style inherited constructors */
  1125. if (!key) {
  1126. ZVAL_STR_COPY(&method_name, mptr->common.function_name);
  1127. zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &method_name);
  1128. } else if ((mptr->common.fn_flags & ZEND_ACC_CTOR) == 0 ||
  1129. mptr->common.scope == ce ||
  1130. zend_binary_strcasecmp(ZSTR_VAL(key), ZSTR_LEN(key), ZSTR_VAL(mptr->common.function_name), len) == 0) {
  1131. if (mptr->type == ZEND_USER_FUNCTION &&
  1132. (!mptr->op_array.refcount || *mptr->op_array.refcount > 1) &&
  1133. !same_name(key, mptr->common.function_name)) {
  1134. ZVAL_STR_COPY(&method_name, zend_find_alias_name(mptr->common.scope, key));
  1135. zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &method_name);
  1136. } else {
  1137. ZVAL_STR_COPY(&method_name, mptr->common.function_name);
  1138. zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &method_name);
  1139. }
  1140. }
  1141. }
  1142. } ZEND_HASH_FOREACH_END();
  1143. }
  1144. /* }}} */
  1145. /* {{{ proto bool method_exists(object object, string method)
  1146. Checks if the class method exists */
  1147. ZEND_FUNCTION(method_exists)
  1148. {
  1149. zval *klass;
  1150. zend_string *method_name;
  1151. zend_string *lcname;
  1152. zend_class_entry * ce;
  1153. ZEND_PARSE_PARAMETERS_START(2, 2)
  1154. Z_PARAM_ZVAL(klass)
  1155. Z_PARAM_STR(method_name)
  1156. ZEND_PARSE_PARAMETERS_END();
  1157. if (Z_TYPE_P(klass) == IS_OBJECT) {
  1158. ce = Z_OBJCE_P(klass);
  1159. } else if (Z_TYPE_P(klass) == IS_STRING) {
  1160. if ((ce = zend_lookup_class(Z_STR_P(klass))) == NULL) {
  1161. RETURN_FALSE;
  1162. }
  1163. } else {
  1164. RETURN_FALSE;
  1165. }
  1166. lcname = zend_string_tolower(method_name);
  1167. if (zend_hash_exists(&ce->function_table, lcname)) {
  1168. zend_string_release_ex(lcname, 0);
  1169. RETURN_TRUE;
  1170. } else if (Z_TYPE_P(klass) == IS_OBJECT && Z_OBJ_HT_P(klass)->get_method != NULL) {
  1171. zend_object *obj = Z_OBJ_P(klass);
  1172. zend_function *func = Z_OBJ_HT_P(klass)->get_method(&obj, method_name, NULL);
  1173. if (func != NULL) {
  1174. if (func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
  1175. /* Returns true to the fake Closure's __invoke */
  1176. RETVAL_BOOL(func->common.scope == zend_ce_closure
  1177. && zend_string_equals_literal(method_name, ZEND_INVOKE_FUNC_NAME));
  1178. zend_string_release_ex(lcname, 0);
  1179. zend_string_release_ex(func->common.function_name, 0);
  1180. zend_free_trampoline(func);
  1181. return;
  1182. }
  1183. zend_string_release_ex(lcname, 0);
  1184. RETURN_TRUE;
  1185. }
  1186. }
  1187. zend_string_release_ex(lcname, 0);
  1188. RETURN_FALSE;
  1189. }
  1190. /* }}} */
  1191. /* {{{ proto bool property_exists(mixed object_or_class, string property_name)
  1192. Checks if the object or class has a property */
  1193. ZEND_FUNCTION(property_exists)
  1194. {
  1195. zval *object;
  1196. zend_string *property;
  1197. zend_class_entry *ce;
  1198. zend_property_info *property_info;
  1199. zval property_z;
  1200. if (zend_parse_parameters(ZEND_NUM_ARGS(), "zS", &object, &property) == FAILURE) {
  1201. return;
  1202. }
  1203. if (property == NULL) {
  1204. RETURN_FALSE;
  1205. }
  1206. if (Z_TYPE_P(object) == IS_STRING) {
  1207. ce = zend_lookup_class(Z_STR_P(object));
  1208. if (!ce) {
  1209. RETURN_FALSE;
  1210. }
  1211. } else if (Z_TYPE_P(object) == IS_OBJECT) {
  1212. ce = Z_OBJCE_P(object);
  1213. } else {
  1214. zend_error(E_WARNING, "First parameter must either be an object or the name of an existing class");
  1215. RETURN_NULL();
  1216. }
  1217. if ((property_info = zend_hash_find_ptr(&ce->properties_info, property)) != NULL
  1218. && (property_info->flags & ZEND_ACC_SHADOW) == 0) {
  1219. RETURN_TRUE;
  1220. }
  1221. ZVAL_STR(&property_z, property);
  1222. if (Z_TYPE_P(object) == IS_OBJECT &&
  1223. Z_OBJ_HANDLER_P(object, has_property) &&
  1224. Z_OBJ_HANDLER_P(object, has_property)(object, &property_z, 2, NULL)) {
  1225. RETURN_TRUE;
  1226. }
  1227. RETURN_FALSE;
  1228. }
  1229. /* }}} */
  1230. /* {{{ proto bool class_exists(string classname [, bool autoload])
  1231. Checks if the class exists */
  1232. ZEND_FUNCTION(class_exists)
  1233. {
  1234. zend_string *class_name;
  1235. zend_string *lc_name;
  1236. zend_class_entry *ce;
  1237. zend_bool autoload = 1;
  1238. ZEND_PARSE_PARAMETERS_START(1, 2)
  1239. Z_PARAM_STR(class_name)
  1240. Z_PARAM_OPTIONAL
  1241. Z_PARAM_BOOL(autoload)
  1242. ZEND_PARSE_PARAMETERS_END();
  1243. if (!autoload) {
  1244. if (ZSTR_VAL(class_name)[0] == '\\') {
  1245. /* Ignore leading "\" */
  1246. lc_name = zend_string_alloc(ZSTR_LEN(class_name) - 1, 0);
  1247. zend_str_tolower_copy(ZSTR_VAL(lc_name), ZSTR_VAL(class_name) + 1, ZSTR_LEN(class_name) - 1);
  1248. } else {
  1249. lc_name = zend_string_tolower(class_name);
  1250. }
  1251. ce = zend_hash_find_ptr(EG(class_table), lc_name);
  1252. zend_string_release_ex(lc_name, 0);
  1253. } else {
  1254. ce = zend_lookup_class(class_name);
  1255. }
  1256. if (ce) {
  1257. RETURN_BOOL((ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT)) == 0);
  1258. } else {
  1259. RETURN_FALSE;
  1260. }
  1261. }
  1262. /* }}} */
  1263. /* {{{ proto bool interface_exists(string classname [, bool autoload])
  1264. Checks if the class exists */
  1265. ZEND_FUNCTION(interface_exists)
  1266. {
  1267. zend_string *iface_name, *lc_name;
  1268. zend_class_entry *ce;
  1269. zend_bool autoload = 1;
  1270. ZEND_PARSE_PARAMETERS_START(1, 2)
  1271. Z_PARAM_STR(iface_name)
  1272. Z_PARAM_OPTIONAL
  1273. Z_PARAM_BOOL(autoload)
  1274. ZEND_PARSE_PARAMETERS_END();
  1275. if (!autoload) {
  1276. if (ZSTR_VAL(iface_name)[0] == '\\') {
  1277. /* Ignore leading "\" */
  1278. lc_name = zend_string_alloc(ZSTR_LEN(iface_name) - 1, 0);
  1279. zend_str_tolower_copy(ZSTR_VAL(lc_name), ZSTR_VAL(iface_name) + 1, ZSTR_LEN(iface_name) - 1);
  1280. } else {
  1281. lc_name = zend_string_tolower(iface_name);
  1282. }
  1283. ce = zend_hash_find_ptr(EG(class_table), lc_name);
  1284. zend_string_release_ex(lc_name, 0);
  1285. RETURN_BOOL(ce && ce->ce_flags & ZEND_ACC_INTERFACE);
  1286. }
  1287. ce = zend_lookup_class(iface_name);
  1288. if (ce) {
  1289. RETURN_BOOL((ce->ce_flags & ZEND_ACC_INTERFACE) > 0);
  1290. } else {
  1291. RETURN_FALSE;
  1292. }
  1293. }
  1294. /* }}} */
  1295. /* {{{ proto bool trait_exists(string traitname [, bool autoload])
  1296. Checks if the trait exists */
  1297. ZEND_FUNCTION(trait_exists)
  1298. {
  1299. zend_string *trait_name, *lc_name;
  1300. zend_class_entry *ce;
  1301. zend_bool autoload = 1;
  1302. ZEND_PARSE_PARAMETERS_START(1, 2)
  1303. Z_PARAM_STR(trait_name)
  1304. Z_PARAM_OPTIONAL
  1305. Z_PARAM_BOOL(autoload)
  1306. ZEND_PARSE_PARAMETERS_END();
  1307. if (!autoload) {
  1308. if (ZSTR_VAL(trait_name)[0] == '\\') {
  1309. /* Ignore leading "\" */
  1310. lc_name = zend_string_alloc(ZSTR_LEN(trait_name) - 1, 0);
  1311. zend_str_tolower_copy(ZSTR_VAL(lc_name), ZSTR_VAL(trait_name) + 1, ZSTR_LEN(trait_name) - 1);
  1312. } else {
  1313. lc_name = zend_string_tolower(trait_name);
  1314. }
  1315. ce = zend_hash_find_ptr(EG(class_table), lc_name);
  1316. zend_string_release_ex(lc_name, 0);
  1317. } else {
  1318. ce = zend_lookup_class(trait_name);
  1319. }
  1320. if (ce) {
  1321. RETURN_BOOL((ce->ce_flags & ZEND_ACC_TRAIT) != 0);
  1322. } else {
  1323. RETURN_FALSE;
  1324. }
  1325. }
  1326. /* }}} */
  1327. /* {{{ proto bool function_exists(string function_name)
  1328. Checks if the function exists */
  1329. ZEND_FUNCTION(function_exists)
  1330. {
  1331. zend_string *name;
  1332. zend_function *func;
  1333. zend_string *lcname;
  1334. ZEND_PARSE_PARAMETERS_START(1, 1)
  1335. Z_PARAM_STR(name)
  1336. ZEND_PARSE_PARAMETERS_END();
  1337. if (ZSTR_VAL(name)[0] == '\\') {
  1338. /* Ignore leading "\" */
  1339. lcname = zend_string_alloc(ZSTR_LEN(name) - 1, 0);
  1340. zend_str_tolower_copy(ZSTR_VAL(lcname), ZSTR_VAL(name) + 1, ZSTR_LEN(name) - 1);
  1341. } else {
  1342. lcname = zend_string_tolower(name);
  1343. }
  1344. func = zend_hash_find_ptr(EG(function_table), lcname);
  1345. zend_string_release_ex(lcname, 0);
  1346. /*
  1347. * A bit of a hack, but not a bad one: we see if the handler of the function
  1348. * is actually one that displays "function is disabled" message.
  1349. */
  1350. RETURN_BOOL(func && (func->type != ZEND_INTERNAL_FUNCTION ||
  1351. func->internal_function.handler != zif_display_disabled_function));
  1352. }
  1353. /* }}} */
  1354. /* {{{ proto bool class_alias(string user_class_name , string alias_name [, bool autoload])
  1355. Creates an alias for user defined class */
  1356. ZEND_FUNCTION(class_alias)
  1357. {
  1358. zend_string *class_name;
  1359. char *alias_name;
  1360. zend_class_entry *ce;
  1361. size_t alias_name_len;
  1362. zend_bool autoload = 1;
  1363. if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ss|b", &class_name, &alias_name, &alias_name_len, &autoload) == FAILURE) {
  1364. return;
  1365. }
  1366. ce = zend_lookup_class_ex(class_name, NULL, autoload);
  1367. if (ce) {
  1368. if (ce->type == ZEND_USER_CLASS) {
  1369. if (zend_register_class_alias_ex(alias_name, alias_name_len, ce, 0) == SUCCESS) {
  1370. RETURN_TRUE;
  1371. } else {
  1372. zend_error(E_WARNING, "Cannot declare %s %s, because the name is already in use", zend_get_object_type(ce), alias_name);
  1373. RETURN_FALSE;
  1374. }
  1375. } else {
  1376. zend_error(E_WARNING, "First argument of class_alias() must be a name of user defined class");
  1377. RETURN_FALSE;
  1378. }
  1379. } else {
  1380. zend_error(E_WARNING, "Class '%s' not found", ZSTR_VAL(class_name));
  1381. RETURN_FALSE;
  1382. }
  1383. }
  1384. /* }}} */
  1385. /* {{{ proto array get_included_files(void)
  1386. Returns an array with the file names that were include_once()'d */
  1387. ZEND_FUNCTION(get_included_files)
  1388. {
  1389. zend_string *entry;
  1390. if (zend_parse_parameters_none() == FAILURE) {
  1391. return;
  1392. }
  1393. array_init(return_value);
  1394. ZEND_HASH_FOREACH_STR_KEY(&EG(included_files), entry) {
  1395. if (entry) {
  1396. add_next_index_str(return_value, zend_string_copy(entry));
  1397. }
  1398. } ZEND_HASH_FOREACH_END();
  1399. }
  1400. /* }}} */
  1401. /* {{{ proto void trigger_error(string message [, int error_type])
  1402. Generates a user-level error/warning/notice message */
  1403. ZEND_FUNCTION(trigger_error)
  1404. {
  1405. zend_long error_type = E_USER_NOTICE;
  1406. char *message;
  1407. size_t message_len;
  1408. if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &message, &message_len, &error_type) == FAILURE) {
  1409. return;
  1410. }
  1411. switch (error_type) {
  1412. case E_USER_ERROR:
  1413. case E_USER_WARNING:
  1414. case E_USER_NOTICE:
  1415. case E_USER_DEPRECATED:
  1416. break;
  1417. default:
  1418. zend_error(E_WARNING, "Invalid error type specified");
  1419. RETURN_FALSE;
  1420. break;
  1421. }
  1422. zend_error((int)error_type, "%s", message);
  1423. RETURN_TRUE;
  1424. }
  1425. /* }}} */
  1426. /* {{{ proto string set_error_handler(callable error_handler [, int error_types])
  1427. Sets a user-defined error handler function. Returns the previously defined error handler, or false on error */
  1428. ZEND_FUNCTION(set_error_handler)
  1429. {
  1430. zval *error_handler;
  1431. zend_long error_type = E_ALL;
  1432. if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|l", &error_handler, &error_type) == FAILURE) {
  1433. return;
  1434. }
  1435. if (Z_TYPE_P(error_handler) != IS_NULL) { /* NULL == unset */
  1436. if (!zend_is_callable(error_handler, 0, NULL)) {
  1437. zend_string *error_handler_name = zend_get_callable_name(error_handler);
  1438. zend_error(E_WARNING, "%s() expects the argument (%s) to be a valid callback",
  1439. get_active_function_name(), error_handler_name?ZSTR_VAL(error_handler_name):"unknown");
  1440. zend_string_release_ex(error_handler_name, 0);
  1441. return;
  1442. }
  1443. }
  1444. if (Z_TYPE(EG(user_error_handler)) != IS_UNDEF) {
  1445. ZVAL_COPY(return_value, &EG(user_error_handler));
  1446. }
  1447. zend_stack_push(&EG(user_error_handlers_error_reporting), &EG(user_error_handler_error_reporting));
  1448. zend_stack_push(&EG(user_error_handlers), &EG(user_error_handler));
  1449. if (Z_TYPE_P(error_handler) == IS_NULL) { /* unset user-defined handler */
  1450. ZVAL_UNDEF(&EG(user_error_handler));
  1451. return;
  1452. }
  1453. ZVAL_COPY(&EG(user_error_handler), error_handler);
  1454. EG(user_error_handler_error_reporting) = (int)error_type;
  1455. }
  1456. /* }}} */
  1457. /* {{{ proto void restore_error_handler(void)
  1458. Restores the previously defined error handler function */
  1459. ZEND_FUNCTION(restore_error_handler)
  1460. {
  1461. if (zend_parse_parameters_none() == FAILURE) {
  1462. return;
  1463. }
  1464. if (Z_TYPE(EG(user_error_handler)) != IS_UNDEF) {
  1465. zval zeh;
  1466. ZVAL_COPY_VALUE(&zeh, &EG(user_error_handler));
  1467. ZVAL_UNDEF(&EG(user_error_handler));
  1468. zval_ptr_dtor(&zeh);
  1469. }
  1470. if (zend_stack_is_empty(&EG(user_error_handlers))) {
  1471. ZVAL_UNDEF(&EG(user_error_handler));
  1472. } else {
  1473. zval *tmp;
  1474. EG(user_error_handler_error_reporting) = zend_stack_int_top(&EG(user_error_handlers_error_reporting));
  1475. zend_stack_del_top(&EG(user_error_handlers_error_reporting));
  1476. tmp = zend_stack_top(&EG(user_error_handlers));
  1477. ZVAL_COPY_VALUE(&EG(user_error_handler), tmp);
  1478. zend_stack_del_top(&EG(user_error_handlers));
  1479. }
  1480. RETURN_TRUE;
  1481. }
  1482. /* }}} */
  1483. /* {{{ proto mixed set_exception_handler(callable exception_handler)
  1484. Sets a user-defined exception handler function. Returns the previously defined exception handler, or false on error */
  1485. ZEND_FUNCTION(set_exception_handler)
  1486. {
  1487. zval *exception_handler;
  1488. if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &exception_handler) == FAILURE) {
  1489. return;
  1490. }
  1491. if (Z_TYPE_P(exception_handler) != IS_NULL) { /* NULL == unset */
  1492. if (!zend_is_callable(exception_handler, 0, NULL)) {
  1493. zend_string *exception_handler_name = zend_get_callable_name(exception_handler);
  1494. zend_error(E_WARNING, "%s() expects the argument (%s) to be a valid callback",
  1495. get_active_function_name(), exception_handler_name?ZSTR_VAL(exception_handler_name):"unknown");
  1496. zend_string_release_ex(exception_handler_name, 0);
  1497. return;
  1498. }
  1499. }
  1500. if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) {
  1501. ZVAL_COPY(return_value, &EG(user_exception_handler));
  1502. }
  1503. zend_stack_push(&EG(user_exception_handlers), &EG(user_exception_handler));
  1504. if (Z_TYPE_P(exception_handler) == IS_NULL) { /* unset user-defined handler */
  1505. ZVAL_UNDEF(&EG(user_exception_handler));
  1506. return;
  1507. }
  1508. ZVAL_COPY(&EG(user_exception_handler), exception_handler);
  1509. }
  1510. /* }}} */
  1511. /* {{{ proto void restore_exception_handler(void)
  1512. Restores the previously defined exception handler function */
  1513. ZEND_FUNCTION(restore_exception_handler)
  1514. {
  1515. if (zend_parse_parameters_none() == FAILURE) {
  1516. return;
  1517. }
  1518. if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) {
  1519. zval_ptr_dtor(&EG(user_exception_handler));
  1520. }
  1521. if (zend_stack_is_empty(&EG(user_exception_handlers))) {
  1522. ZVAL_UNDEF(&EG(user_exception_handler));
  1523. } else {
  1524. zval *tmp = zend_stack_top(&EG(user_exception_handlers));
  1525. ZVAL_COPY_VALUE(&EG(user_exception_handler), tmp);
  1526. zend_stack_del_top(&EG(user_exception_handlers));
  1527. }
  1528. RETURN_TRUE;
  1529. }
  1530. /* }}} */
  1531. static int copy_class_or_interface_name(zval *el, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
  1532. {
  1533. zend_class_entry *ce = (zend_class_entry *)Z_PTR_P(el);
  1534. zval *array = va_arg(args, zval *);
  1535. uint32_t mask = va_arg(args, uint32_t);
  1536. uint32_t comply = va_arg(args, uint32_t);
  1537. uint32_t comply_mask = (comply)? mask:0;
  1538. if ((hash_key->key && ZSTR_VAL(hash_key->key)[0] != 0)
  1539. && (comply_mask == (ce->ce_flags & mask))) {
  1540. if (ce->refcount > 1 &&
  1541. !same_name(hash_key->key, ce->name)) {
  1542. add_next_index_str(array, zend_string_copy(hash_key->key));
  1543. } else {
  1544. add_next_index_str(array, zend_string_copy(ce->name));
  1545. }
  1546. }
  1547. return ZEND_HASH_APPLY_KEEP;
  1548. }
  1549. /* }}} */
  1550. /* {{{ proto array get_declared_traits()
  1551. Returns an array of all declared traits. */
  1552. ZEND_FUNCTION(get_declared_traits)
  1553. {
  1554. uint32_t mask = ZEND_ACC_TRAIT;
  1555. uint32_t comply = 1;
  1556. if (zend_parse_parameters_none() == FAILURE) {
  1557. return;
  1558. }
  1559. array_init(return_value);
  1560. zend_hash_apply_with_arguments(EG(class_table), copy_class_or_interface_name, 3, return_value, mask, comply);
  1561. }
  1562. /* }}} */
  1563. /* {{{ proto array get_declared_classes()
  1564. Returns an array of all declared classes. */
  1565. ZEND_FUNCTION(get_declared_classes)
  1566. {
  1567. uint32_t mask = ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT;
  1568. uint32_t comply = 0;
  1569. if (zend_parse_parameters_none() == FAILURE) {
  1570. return;
  1571. }
  1572. array_init(return_value);
  1573. zend_hash_apply_with_arguments(EG(class_table), copy_class_or_interface_name, 3, return_value, mask, comply);
  1574. }
  1575. /* }}} */
  1576. /* {{{ proto array get_declared_interfaces()
  1577. Returns an array of all declared interfaces. */
  1578. ZEND_FUNCTION(get_declared_interfaces)
  1579. {
  1580. uint32_t mask = ZEND_ACC_INTERFACE;
  1581. uint32_t comply = 1;
  1582. if (zend_parse_parameters_none() == FAILURE) {
  1583. return;
  1584. }
  1585. array_init(return_value);
  1586. zend_hash_apply_with_arguments(EG(class_table), copy_class_or_interface_name, 3, return_value, mask, comply);
  1587. }
  1588. /* }}} */
  1589. static int copy_function_name(zval *zv, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
  1590. {
  1591. zend_function *func = Z_PTR_P(zv);
  1592. zval *internal_ar = va_arg(args, zval *),
  1593. *user_ar = va_arg(args, zval *);
  1594. zend_bool *exclude_disabled = va_arg(args, zend_bool *);
  1595. if (hash_key->key == NULL || ZSTR_VAL(hash_key->key)[0] == 0) {
  1596. return 0;
  1597. }
  1598. if (func->type == ZEND_INTERNAL_FUNCTION
  1599. && (!*exclude_disabled || func->internal_function.handler != ZEND_FN(display_disabled_function))) {
  1600. add_next_index_str(internal_ar, zend_string_copy(hash_key->key));
  1601. } else if (func->type == ZEND_USER_FUNCTION) {
  1602. add_next_index_str(user_ar, zend_string_copy(hash_key->key));
  1603. }
  1604. return 0;
  1605. }
  1606. /* }}} */
  1607. /* {{{ proto array get_defined_functions(void)
  1608. Returns an array of all defined functions */
  1609. ZEND_FUNCTION(get_defined_functions)
  1610. {
  1611. zval internal, user;
  1612. zend_bool exclude_disabled = 0;
  1613. if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &exclude_disabled) == FAILURE) {
  1614. return;
  1615. }
  1616. array_init(&internal);
  1617. array_init(&user);
  1618. array_init(return_value);
  1619. zend_hash_apply_with_arguments(EG(function_table), copy_function_name, 3, &internal, &user, &exclude_disabled);
  1620. zend_hash_str_add_new(Z_ARRVAL_P(return_value), "internal", sizeof("internal")-1, &internal);
  1621. zend_hash_str_add_new(Z_ARRVAL_P(return_value), "user", sizeof("user")-1, &user);
  1622. }
  1623. /* }}} */
  1624. /* {{{ proto array get_defined_vars(void)
  1625. Returns an associative array of names and values of all currently defined variable names (variables in the current scope) */
  1626. ZEND_FUNCTION(get_defined_vars)
  1627. {
  1628. zend_array *symbol_table;
  1629. if (zend_forbid_dynamic_call("get_defined_vars()") == FAILURE) {
  1630. return;
  1631. }
  1632. symbol_table = zend_rebuild_symbol_table();
  1633. if (UNEXPECTED(symbol_table == NULL)) {
  1634. return;
  1635. }
  1636. RETURN_ARR(zend_array_dup(symbol_table));
  1637. }
  1638. /* }}} */
  1639. #define LAMBDA_TEMP_FUNCNAME "__lambda_func"
  1640. /* {{{ proto string create_function(string args, string code)
  1641. Creates an anonymous function, and returns its name (funny, eh?) */
  1642. ZEND_FUNCTION(create_function)
  1643. {
  1644. zend_string *function_name;
  1645. char *eval_code, *function_args, *function_code;
  1646. size_t eval_code_length, function_args_len, function_code_len;
  1647. int retval;
  1648. char *eval_name;
  1649. if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &function_args, &function_args_len, &function_code, &function_code_len) == FAILURE) {
  1650. return;
  1651. }
  1652. eval_code = (char *) emalloc(sizeof("function " LAMBDA_TEMP_FUNCNAME)
  1653. +function_args_len
  1654. +2 /* for the args parentheses */
  1655. +2 /* for the curly braces */
  1656. +function_code_len);
  1657. eval_code_length = sizeof("function " LAMBDA_TEMP_FUNCNAME "(") - 1;
  1658. memcpy(eval_code, "function " LAMBDA_TEMP_FUNCNAME "(", eval_code_length);
  1659. memcpy(eval_code + eval_code_length, function_args, function_args_len);
  1660. eval_code_length += function_args_len;
  1661. eval_code[eval_code_length++] = ')';
  1662. eval_code[eval_code_length++] = '{';
  1663. memcpy(eval_code + eval_code_length, function_code, function_code_len);
  1664. eval_code_length += function_code_len;
  1665. eval_code[eval_code_length++] = '}';
  1666. eval_code[eval_code_length] = '\0';
  1667. eval_name = zend_make_compiled_string_description("runtime-created function");
  1668. retval = zend_eval_stringl(eval_code, eval_code_length, NULL, eval_name);
  1669. efree(eval_code);
  1670. efree(eval_name);
  1671. if (retval==SUCCESS) {
  1672. zend_op_array *func;
  1673. HashTable *static_variables;
  1674. func = zend_hash_str_find_ptr(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME)-1);
  1675. if (!func) {
  1676. zend_error_noreturn(E_CORE_ERROR, "Unexpected inconsistency in create_function()");
  1677. RETURN_FALSE;
  1678. }
  1679. if (func->refcount) {
  1680. (*func->refcount)++;
  1681. }
  1682. static_variables = func->static_variables;
  1683. func->static_variables = NULL;
  1684. zend_hash_str_del(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME)-1);
  1685. func->static_variables = static_variables;
  1686. function_name = zend_string_alloc(sizeof("0lambda_")+MAX_LENGTH_OF_LONG, 0);
  1687. ZSTR_VAL(function_name)[0] = '\0';
  1688. do {
  1689. ZSTR_LEN(function_name) = snprintf(ZSTR_VAL(function_name) + 1, sizeof("lambda_")+MAX_LENGTH_OF_LONG, "lambda_%d", ++EG(lambda_count)) + 1;
  1690. } while (zend_hash_add_ptr(EG(function_table), function_name, func) == NULL);
  1691. RETURN_NEW_STR(function_name);
  1692. } else {
  1693. zend_hash_str_del(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME)-1);
  1694. RETURN_FALSE;
  1695. }
  1696. }
  1697. /* }}} */
  1698. #if ZEND_DEBUG && defined(ZTS)
  1699. ZEND_FUNCTION(zend_thread_id)
  1700. {
  1701. RETURN_LONG((zend_long)tsrm_thread_id());
  1702. }
  1703. #endif
  1704. /* {{{ proto string get_resource_type(resource res)
  1705. Get the resource type name for a given resource */
  1706. ZEND_FUNCTION(get_resource_type)
  1707. {
  1708. const char *resource_type;
  1709. zval *z_resource_type;
  1710. if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_resource_type) == FAILURE) {
  1711. return;
  1712. }
  1713. resource_type = zend_rsrc_list_get_rsrc_type(Z_RES_P(z_resource_type));
  1714. if (resource_type) {
  1715. RETURN_STRING(resource_type);
  1716. } else {
  1717. RETURN_STRING("Unknown");
  1718. }
  1719. }
  1720. /* }}} */
  1721. /* {{{ proto array get_resources([string resouce_type])
  1722. Get an array with all active resources */
  1723. ZEND_FUNCTION(get_resources)
  1724. {
  1725. zend_string *type = NULL;
  1726. zend_string *key;
  1727. zend_ulong index;
  1728. zval *val;
  1729. if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S", &type) == FAILURE) {
  1730. return;
  1731. }
  1732. if (!type) {
  1733. array_init(return_value);
  1734. ZEND_HASH_FOREACH_KEY_VAL(&EG(regular_list), index, key, val) {
  1735. if (!key) {
  1736. Z_ADDREF_P(val);
  1737. zend_hash_index_add_new(Z_ARRVAL_P(return_value), index, val);
  1738. }
  1739. } ZEND_HASH_FOREACH_END();
  1740. } else if (zend_string_equals_literal(type, "Unknown")) {
  1741. array_init(return_value);
  1742. ZEND_HASH_FOREACH_KEY_VAL(&EG(regular_list), index, key, val) {
  1743. if (!key && Z_RES_TYPE_P(val) <= 0) {
  1744. Z_ADDREF_P(val);
  1745. zend_hash_index_add_new(Z_ARRVAL_P(return_value), index, val);
  1746. }
  1747. } ZEND_HASH_FOREACH_END();
  1748. } else {
  1749. int id = zend_fetch_list_dtor_id(ZSTR_VAL(type));
  1750. if (id <= 0) {
  1751. zend_error(E_WARNING, "get_resources(): Unknown resource type '%s'", ZSTR_VAL(type));
  1752. RETURN_FALSE;
  1753. }
  1754. array_init(return_value);
  1755. ZEND_HASH_FOREACH_KEY_VAL(&EG(regular_list), index, key, val) {
  1756. if (!key && Z_RES_TYPE_P(val) == id) {
  1757. Z_ADDREF_P(val);
  1758. zend_hash_index_add_new(Z_ARRVAL_P(return_value), index, val);
  1759. }
  1760. } ZEND_HASH_FOREACH_END();
  1761. }
  1762. }
  1763. /* }}} */
  1764. static int add_extension_info(zval *item, void *arg) /* {{{ */
  1765. {
  1766. zval *name_array = (zval *)arg;
  1767. zend_module_entry *module = (zend_module_entry*)Z_PTR_P(item);
  1768. add_next_index_string(name_array, module->name);
  1769. return 0;
  1770. }
  1771. /* }}} */
  1772. static int add_zendext_info(zend_extension *ext, void *arg) /* {{{ */
  1773. {
  1774. zval *name_array = (zval *)arg;
  1775. add_next_index_string(name_array, ext->name);
  1776. return 0;
  1777. }
  1778. /* }}} */
  1779. static int add_constant_info(zval *item, void *arg) /* {{{ */
  1780. {
  1781. zval *name_array = (zval *)arg;
  1782. zend_constant *constant = (zend_constant*)Z_PTR_P(item);
  1783. zval const_val;
  1784. if (!constant->name) {
  1785. /* skip special constants */
  1786. return 0;
  1787. }
  1788. ZVAL_COPY_OR_DUP(&const_val, &constant->value);
  1789. zend_hash_add_new(Z_ARRVAL_P(name_array), constant->name, &const_val);
  1790. return 0;
  1791. }
  1792. /* }}} */
  1793. /* {{{ proto array get_loaded_extensions([bool zend_extensions])
  1794. Return an array containing names of loaded extensions */
  1795. ZEND_FUNCTION(get_loaded_extensions)
  1796. {
  1797. zend_bool zendext = 0;
  1798. if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &zendext) == FAILURE) {
  1799. return;
  1800. }
  1801. array_init(return_value);
  1802. if (zendext) {
  1803. zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t)add_zendext_info, return_value);
  1804. } else {
  1805. zend_hash_apply_with_argument(&module_registry, add_extension_info, return_value);
  1806. }
  1807. }
  1808. /* }}} */
  1809. /* {{{ proto array get_defined_constants([bool categorize])
  1810. Return an array containing the names and values of all defined constants */
  1811. ZEND_FUNCTION(get_defined_constants)
  1812. {
  1813. zend_bool categorize = 0;
  1814. if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &categorize) == FAILURE) {
  1815. return;
  1816. }
  1817. array_init(return_value);
  1818. if (categorize) {
  1819. zend_constant *val;
  1820. int module_number;
  1821. zval *modules, const_val;
  1822. char **module_names;
  1823. zend_module_entry *module;
  1824. int i = 1;
  1825. modules = ecalloc(zend_hash_num_elements(&module_registry) + 2, sizeof(zval));
  1826. module_names = emalloc((zend_hash_num_elements(&module_registry) + 2) * sizeof(char *));
  1827. module_names[0] = "internal";
  1828. ZEND_HASH_FOREACH_PTR(&module_registry, module) {
  1829. module_names[module->module_number] = (char *)module->name;
  1830. i++;
  1831. } ZEND_HASH_FOREACH_END();
  1832. module_names[i] = "user";
  1833. ZEND_HASH_FOREACH_PTR(EG(zend_constants), val) {
  1834. if (!val->name) {
  1835. /* skip special constants */
  1836. continue;
  1837. }
  1838. if (ZEND_CONSTANT_MODULE_NUMBER(val) == PHP_USER_CONSTANT) {
  1839. module_number = i;
  1840. } else if (ZEND_CONSTANT_MODULE_NUMBER(val) > i) {
  1841. /* should not happen */
  1842. continue;
  1843. } else {
  1844. module_number = ZEND_CONSTANT_MODULE_NUMBER(val);
  1845. }
  1846. if (Z_TYPE(modules[module_number]) == IS_UNDEF) {
  1847. array_init(&modules[module_number]);
  1848. add_assoc_zval(return_value, module_names[module_number], &modules[module_number]);
  1849. }
  1850. ZVAL_COPY_OR_DUP(&const_val, &val->value);
  1851. zend_hash_add_new(Z_ARRVAL(modules[module_number]), val->name, &const_val);
  1852. } ZEND_HASH_FOREACH_END();
  1853. efree(module_names);
  1854. efree(modules);
  1855. } else {
  1856. zend_hash_apply_with_argument(EG(zend_constants), add_constant_info, return_value);
  1857. }
  1858. }
  1859. /* }}} */
  1860. static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array) /* {{{ */
  1861. {
  1862. uint32_t num_args = ZEND_CALL_NUM_ARGS(call);
  1863. if (num_args) {
  1864. uint32_t i = 0;
  1865. zval *p = ZEND_CALL_ARG(call, 1);
  1866. array_init_size(arg_array, num_args);
  1867. zend_hash_real_init_packed(Z_ARRVAL_P(arg_array));
  1868. ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(arg_array)) {
  1869. if (call->func->type == ZEND_USER_FUNCTION) {
  1870. uint32_t first_extra_arg = MIN(num_args, call->func->op_array.num_args);
  1871. if (UNEXPECTED(ZEND_CALL_INFO(call) & ZEND_CALL_HAS_SYMBOL_TABLE)) {
  1872. /* In case of attached symbol_table, values on stack may be invalid
  1873. * and we have to access them through symbol_table
  1874. * See: https://bugs.php.net/bug.php?id=73156
  1875. */
  1876. zend_string *arg_name;
  1877. zval *arg;
  1878. while (i < first_extra_arg) {
  1879. arg_name = call->func->op_array.vars[i];
  1880. arg = zend_hash_find_ex_ind(call->symbol_table, arg_name, 1);
  1881. if (arg) {
  1882. if (Z_OPT_REFCOUNTED_P(arg)) {
  1883. Z_ADDREF_P(arg);
  1884. }
  1885. ZEND_HASH_FILL_ADD(arg);
  1886. } else {
  1887. ZEND_HASH_FILL_ADD(&EG(uninitialized_zval));
  1888. }
  1889. i++;
  1890. }
  1891. } else {
  1892. while (i < first_extra_arg) {
  1893. if (EXPECTED(Z_TYPE_INFO_P(p) != IS_UNDEF)) {
  1894. if (Z_OPT_REFCOUNTED_P(p)) {
  1895. Z_ADDREF_P(p);
  1896. }
  1897. ZEND_HASH_FILL_ADD(p);
  1898. } else {
  1899. ZEND_HASH_FILL_ADD(&EG(uninitialized_zval));
  1900. }
  1901. p++;
  1902. i++;
  1903. }
  1904. }
  1905. p = ZEND_CALL_VAR_NUM(call, call->func->op_array.last_var + call->func->op_array.T);
  1906. }
  1907. while (i < num_args) {
  1908. if (EXPECTED(Z_TYPE_INFO_P(p) != IS_UNDEF)) {
  1909. if (Z_OPT_REFCOUNTED_P(p)) {
  1910. Z_ADDREF_P(p);
  1911. }
  1912. ZEND_HASH_FILL_ADD(p);
  1913. } else {
  1914. ZEND_HASH_FILL_ADD(&EG(uninitialized_zval));
  1915. }
  1916. p++;
  1917. i++;
  1918. }
  1919. } ZEND_HASH_FILL_END();
  1920. Z_ARRVAL_P(arg_array)->nNumOfElements = num_args;
  1921. } else {
  1922. ZVAL_EMPTY_ARRAY(arg_array);
  1923. }
  1924. }
  1925. /* }}} */
  1926. void debug_print_backtrace_args(zval *arg_array) /* {{{ */
  1927. {
  1928. zval *tmp;
  1929. int i = 0;
  1930. ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(arg_array), tmp) {
  1931. if (i++) {
  1932. ZEND_PUTS(", ");
  1933. }
  1934. zend_print_flat_zval_r(tmp);
  1935. } ZEND_HASH_FOREACH_END();
  1936. }
  1937. /* }}} */
  1938. /* {{{ proto void debug_print_backtrace([int options[, int limit]]) */
  1939. ZEND_FUNCTION(debug_print_backtrace)
  1940. {
  1941. zend_execute_data *call, *ptr, *skip;
  1942. zend_object *object;
  1943. int lineno, frameno = 0;
  1944. zend_function *func;
  1945. const char *function_name;
  1946. const char *filename;
  1947. zend_string *class_name = NULL;
  1948. char *call_type;
  1949. const char *include_filename = NULL;
  1950. zval arg_array;
  1951. int indent = 0;
  1952. zend_long options = 0;
  1953. zend_long limit = 0;
  1954. if (zend_parse_parameters(ZEND_NUM_ARGS(), "|ll", &options, &limit) == FAILURE) {
  1955. return;
  1956. }
  1957. ZVAL_UNDEF(&arg_array);
  1958. ptr = EX(prev_execute_data);
  1959. /* skip debug_backtrace() */
  1960. call = ptr;
  1961. ptr = ptr->prev_execute_data;
  1962. while (ptr && (limit == 0 || frameno < limit)) {
  1963. frameno++;
  1964. class_name = NULL;
  1965. call_type = NULL;
  1966. ZVAL_UNDEF(&arg_array);
  1967. ptr = zend_generator_check_placeholder_frame(ptr);
  1968. skip = ptr;
  1969. /* skip internal handler */
  1970. if ((!skip->func || !ZEND_USER_CODE(skip->func->common.type)) &&
  1971. skip->prev_execute_data &&
  1972. skip->prev_execute_data->func &&
  1973. ZEND_USER_CODE(skip->prev_execute_data->func->common.type) &&
  1974. skip->prev_execute_data->opline->opcode != ZEND_DO_FCALL &&
  1975. skip->prev_execute_data->opline->opcode != ZEND_DO_ICALL &&
  1976. skip->prev_execute_data->opline->opcode != ZEND_DO_UCALL &&
  1977. skip->prev_execute_data->opline->opcode != ZEND_DO_FCALL_BY_NAME &&
  1978. skip->prev_execute_data->opline->opcode != ZEND_INCLUDE_OR_EVAL) {
  1979. skip = skip->prev_execute_data;
  1980. }
  1981. if (skip->func && ZEND_USER_CODE(skip->func->common.type)) {
  1982. filename = ZSTR_VAL(skip->func->op_array.filename);
  1983. if (skip->opline->opcode == ZEND_HANDLE_EXCEPTION) {
  1984. if (EG(opline_before_exception)) {
  1985. lineno = EG(opline_before_exception)->lineno;
  1986. } else {
  1987. lineno = skip->func->op_array.line_end;
  1988. }
  1989. } else {
  1990. lineno = skip->opline->lineno;
  1991. }
  1992. } else {
  1993. filename = NULL;
  1994. lineno = 0;
  1995. }
  1996. /* $this may be passed into regular internal functions */
  1997. object = (Z_TYPE(call->This) == IS_OBJECT) ? Z_OBJ(call->This) : NULL;
  1998. if (call->func) {
  1999. zend_string *zend_function_name;
  2000. func = call->func;
  2001. if (func->common.scope && func->common.scope->trait_aliases) {
  2002. zend_function_name = zend_resolve_method_name(object ? object->ce : func->common.scope, func);
  2003. } else {
  2004. zend_function_name = func->common.function_name;
  2005. }
  2006. if (zend_function_name != NULL) {
  2007. function_name = ZSTR_VAL(zend_function_name);
  2008. } else {
  2009. function_name = NULL;
  2010. }
  2011. } else {
  2012. func = NULL;
  2013. function_name = NULL;
  2014. }
  2015. if (function_name) {
  2016. if (object) {
  2017. if (func->common.scope) {
  2018. class_name = func->common.scope->name;
  2019. } else if (object->handlers->get_class_name == zend_std_get_class_name) {
  2020. class_name = object->ce->name;
  2021. } else {
  2022. class_name = object->handlers->get_class_name(object);
  2023. }
  2024. call_type = "->";
  2025. } else if (func->common.scope) {
  2026. class_name = func->common.scope->name;
  2027. call_type = "::";
  2028. } else {
  2029. class_name = NULL;
  2030. call_type = NULL;
  2031. }
  2032. if (func->type != ZEND_EVAL_CODE) {
  2033. if ((options & DEBUG_BACKTRACE_IGNORE_ARGS) == 0) {
  2034. debug_backtrace_get_args(call, &arg_array);
  2035. }
  2036. }
  2037. } else {
  2038. /* i know this is kinda ugly, but i'm trying to avoid extra cycles in the main execution loop */
  2039. zend_bool build_filename_arg = 1;
  2040. if (!ptr->func || !ZEND_USER_CODE(ptr->func->common.type) || ptr->opline->opcode != ZEND_INCLUDE_OR_EVAL) {
  2041. /* can happen when calling eval from a custom sapi */
  2042. function_name = "unknown";
  2043. build_filename_arg = 0;
  2044. } else
  2045. switch (ptr->opline->extended_value) {
  2046. case ZEND_EVAL:
  2047. function_name = "eval";
  2048. build_filename_arg = 0;
  2049. break;
  2050. case ZEND_INCLUDE:
  2051. function_name = "include";
  2052. break;
  2053. case ZEND_REQUIRE:
  2054. function_name = "require";
  2055. break;
  2056. case ZEND_INCLUDE_ONCE:
  2057. function_name = "include_once";
  2058. break;
  2059. case ZEND_REQUIRE_ONCE:
  2060. function_name = "require_once";
  2061. break;
  2062. default:
  2063. /* this can actually happen if you use debug_backtrace() in your error_handler and
  2064. * you're in the top-scope */
  2065. function_name = "unknown";
  2066. build_filename_arg = 0;
  2067. break;
  2068. }
  2069. if (build_filename_arg && include_filename) {
  2070. array_init(&arg_array);
  2071. add_next_index_string(&arg_array, (char*)include_filename);
  2072. }
  2073. call_type = NULL;
  2074. }
  2075. zend_printf("#%-2d ", indent);
  2076. if (class_name) {
  2077. ZEND_PUTS(ZSTR_VAL(class_name));
  2078. ZEND_PUTS(call_type);
  2079. if (object
  2080. && !func->common.scope
  2081. && object->handlers->get_class_name != zend_std_get_class_name) {
  2082. zend_string_release_ex(class_name, 0);
  2083. }
  2084. }
  2085. zend_printf("%s(", function_name);
  2086. if (Z_TYPE(arg_array) != IS_UNDEF) {
  2087. debug_print_backtrace_args(&arg_array);
  2088. zval_ptr_dtor(&arg_array);
  2089. }
  2090. if (filename) {
  2091. zend_printf(") called at [%s:%d]\n", filename, lineno);
  2092. } else {
  2093. zend_execute_data *prev_call = skip;
  2094. zend_execute_data *prev = skip->prev_execute_data;
  2095. while (prev) {
  2096. if (prev_call &&
  2097. prev_call->func &&
  2098. !ZEND_USER_CODE(prev_call->func->common.type)) {
  2099. prev = NULL;
  2100. break;
  2101. }
  2102. if (prev->func && ZEND_USER_CODE(prev->func->common.type)) {
  2103. zend_printf(") called at [%s:%d]\n", ZSTR_VAL(prev->func->op_array.filename), prev->opline->lineno);
  2104. break;
  2105. }
  2106. prev_call = prev;
  2107. prev = prev->prev_execute_data;
  2108. }
  2109. if (!prev) {
  2110. ZEND_PUTS(")\n");
  2111. }
  2112. }
  2113. include_filename = filename;
  2114. call = skip;
  2115. ptr = skip->prev_execute_data;
  2116. ++indent;
  2117. }
  2118. }
  2119. /* }}} */
  2120. ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int options, int limit) /* {{{ */
  2121. {
  2122. zend_execute_data *ptr, *skip, *call = NULL;
  2123. zend_object *object;
  2124. int lineno, frameno = 0;
  2125. zend_function *func;
  2126. zend_string *function_name;
  2127. zend_string *filename;
  2128. zend_string *include_filename = NULL;
  2129. zval stack_frame, tmp;
  2130. array_init(return_value);
  2131. if (!(ptr = EG(current_execute_data))) {
  2132. return;
  2133. }
  2134. if (!ptr->func || !ZEND_USER_CODE(ptr->func->common.type)) {
  2135. call = ptr;
  2136. ptr = ptr->prev_execute_data;
  2137. }
  2138. if (ptr) {
  2139. if (skip_last) {
  2140. /* skip debug_backtrace() */
  2141. call = ptr;
  2142. ptr = ptr->prev_execute_data;
  2143. } else {
  2144. /* skip "new Exception()" */
  2145. if (ptr->func && ZEND_USER_CODE(ptr->func->common.type) && (ptr->opline->opcode == ZEND_NEW)) {
  2146. call = ptr;
  2147. ptr = ptr->prev_execute_data;
  2148. }
  2149. }
  2150. if (!call) {
  2151. call = ptr;
  2152. ptr = ptr->prev_execute_data;
  2153. }
  2154. }
  2155. while (ptr && (limit == 0 || frameno < limit)) {
  2156. frameno++;
  2157. array_init(&stack_frame);
  2158. ptr = zend_generator_check_placeholder_frame(ptr);
  2159. skip = ptr;
  2160. /* skip internal handler */
  2161. if ((!skip->func || !ZEND_USER_CODE(skip->func->common.type)) &&
  2162. skip->prev_execute_data &&
  2163. skip->prev_execute_data->func &&
  2164. ZEND_USER_CODE(skip->prev_execute_data->func->common.type) &&
  2165. skip->prev_execute_data->opline->opcode != ZEND_DO_FCALL &&
  2166. skip->prev_execute_data->opline->opcode != ZEND_DO_ICALL &&
  2167. skip->prev_execute_data->opline->opcode != ZEND_DO_UCALL &&
  2168. skip->prev_execute_data->opline->opcode != ZEND_DO_FCALL_BY_NAME &&
  2169. skip->prev_execute_data->opline->opcode != ZEND_INCLUDE_OR_EVAL) {
  2170. skip = skip->prev_execute_data;
  2171. }
  2172. if (skip->func && ZEND_USER_CODE(skip->func->common.type)) {
  2173. filename = skip->func->op_array.filename;
  2174. if (skip->opline->opcode == ZEND_HANDLE_EXCEPTION) {
  2175. if (EG(opline_before_exception)) {
  2176. lineno = EG(opline_before_exception)->lineno;
  2177. } else {
  2178. lineno = skip->func->op_array.line_end;
  2179. }
  2180. } else {
  2181. lineno = skip->opline->lineno;
  2182. }
  2183. ZVAL_STR_COPY(&tmp, filename);
  2184. zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_FILE), &tmp);
  2185. ZVAL_LONG(&tmp, lineno);
  2186. zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_LINE), &tmp);
  2187. /* try to fetch args only if an FCALL was just made - elsewise we're in the middle of a function
  2188. * and debug_baktrace() might have been called by the error_handler. in this case we don't
  2189. * want to pop anything of the argument-stack */
  2190. } else {
  2191. zend_execute_data *prev_call = skip;
  2192. zend_execute_data *prev = skip->prev_execute_data;
  2193. while (prev) {
  2194. if (prev_call &&
  2195. prev_call->func &&
  2196. !ZEND_USER_CODE(prev_call->func->common.type) &&
  2197. !(prev_call->func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
  2198. break;
  2199. }
  2200. if (prev->func && ZEND_USER_CODE(prev->func->common.type)) {
  2201. ZVAL_STR_COPY(&tmp, prev->func->op_array.filename);
  2202. zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_FILE), &tmp);
  2203. ZVAL_LONG(&tmp, prev->opline->lineno);
  2204. zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_LINE), &tmp);
  2205. break;
  2206. }
  2207. prev_call = prev;
  2208. prev = prev->prev_execute_data;
  2209. }
  2210. filename = NULL;
  2211. }
  2212. /* $this may be passed into regular internal functions */
  2213. object = (call && (Z_TYPE(call->This) == IS_OBJECT)) ? Z_OBJ(call->This) : NULL;
  2214. if (call && call->func) {
  2215. func = call->func;
  2216. function_name = (func->common.scope &&
  2217. func->common.scope->trait_aliases) ?
  2218. zend_resolve_method_name(
  2219. (object ? object->ce : func->common.scope), func) :
  2220. func->common.function_name;
  2221. } else {
  2222. func = NULL;
  2223. function_name = NULL;
  2224. }
  2225. if (function_name) {
  2226. ZVAL_STR_COPY(&tmp, function_name);
  2227. zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_FUNCTION), &tmp);
  2228. if (object) {
  2229. if (func->common.scope) {
  2230. ZVAL_STR_COPY(&tmp, func->common.scope->name);
  2231. } else if (object->handlers->get_class_name == zend_std_get_class_name) {
  2232. ZVAL_STR_COPY(&tmp, object->ce->name);
  2233. } else {
  2234. ZVAL_STR(&tmp, object->handlers->get_class_name(object));
  2235. }
  2236. zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_CLASS), &tmp);
  2237. if ((options & DEBUG_BACKTRACE_PROVIDE_OBJECT) != 0) {
  2238. ZVAL_OBJ(&tmp, object);
  2239. zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_OBJECT), &tmp);
  2240. Z_ADDREF(tmp);
  2241. }
  2242. ZVAL_INTERNED_STR(&tmp, ZSTR_KNOWN(ZEND_STR_OBJECT_OPERATOR));
  2243. zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_TYPE), &tmp);
  2244. } else if (func->common.scope) {
  2245. ZVAL_STR_COPY(&tmp, func->common.scope->name);
  2246. zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_CLASS), &tmp);
  2247. ZVAL_INTERNED_STR(&tmp, ZSTR_KNOWN(ZEND_STR_PAAMAYIM_NEKUDOTAYIM));
  2248. zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_TYPE), &tmp);
  2249. }
  2250. if ((options & DEBUG_BACKTRACE_IGNORE_ARGS) == 0 &&
  2251. func->type != ZEND_EVAL_CODE) {
  2252. debug_backtrace_get_args(call, &tmp);
  2253. zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_ARGS), &tmp);
  2254. }
  2255. } else {
  2256. /* i know this is kinda ugly, but i'm trying to avoid extra cycles in the main execution loop */
  2257. zend_bool build_filename_arg = 1;
  2258. zend_string *pseudo_function_name;
  2259. if (!ptr->func || !ZEND_USER_CODE(ptr->func->common.type) || ptr->opline->opcode != ZEND_INCLUDE_OR_EVAL) {
  2260. /* can happen when calling eval from a custom sapi */
  2261. pseudo_function_name = ZSTR_KNOWN(ZEND_STR_UNKNOWN);
  2262. build_filename_arg = 0;
  2263. } else
  2264. switch (ptr->opline->extended_value) {
  2265. case ZEND_EVAL:
  2266. pseudo_function_name = ZSTR_KNOWN(ZEND_STR_EVAL);
  2267. build_filename_arg = 0;
  2268. break;
  2269. case ZEND_INCLUDE:
  2270. pseudo_function_name = ZSTR_KNOWN(ZEND_STR_INCLUDE);
  2271. break;
  2272. case ZEND_REQUIRE:
  2273. pseudo_function_name = ZSTR_KNOWN(ZEND_STR_REQUIRE);
  2274. break;
  2275. case ZEND_INCLUDE_ONCE:
  2276. pseudo_function_name = ZSTR_KNOWN(ZEND_STR_INCLUDE_ONCE);
  2277. break;
  2278. case ZEND_REQUIRE_ONCE:
  2279. pseudo_function_name = ZSTR_KNOWN(ZEND_STR_REQUIRE_ONCE);
  2280. break;
  2281. default:
  2282. /* this can actually happen if you use debug_backtrace() in your error_handler and
  2283. * you're in the top-scope */
  2284. pseudo_function_name = ZSTR_KNOWN(ZEND_STR_UNKNOWN);
  2285. build_filename_arg = 0;
  2286. break;
  2287. }
  2288. if (build_filename_arg && include_filename) {
  2289. zval arg_array;
  2290. array_init(&arg_array);
  2291. /* include_filename always points to the last filename of the last last called-function.
  2292. if we have called include in the frame above - this is the file we have included.
  2293. */
  2294. ZVAL_STR_COPY(&tmp, include_filename);
  2295. zend_hash_next_index_insert_new(Z_ARRVAL(arg_array), &tmp);
  2296. zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_ARGS), &arg_array);
  2297. }
  2298. ZVAL_INTERNED_STR(&tmp, pseudo_function_name);
  2299. zend_hash_add_new(Z_ARRVAL(stack_frame), ZSTR_KNOWN(ZEND_STR_FUNCTION), &tmp);
  2300. }
  2301. zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &stack_frame);
  2302. include_filename = filename;
  2303. call = skip;
  2304. ptr = skip->prev_execute_data;
  2305. }
  2306. }
  2307. /* }}} */
  2308. /* {{{ proto array debug_backtrace([int options[, int limit]])
  2309. Return backtrace as array */
  2310. ZEND_FUNCTION(debug_backtrace)
  2311. {
  2312. zend_long options = DEBUG_BACKTRACE_PROVIDE_OBJECT;
  2313. zend_long limit = 0;
  2314. if (zend_parse_parameters(ZEND_NUM_ARGS(), "|ll", &options, &limit) == FAILURE) {
  2315. return;
  2316. }
  2317. zend_fetch_debug_backtrace(return_value, 1, options, limit);
  2318. }
  2319. /* }}} */
  2320. /* {{{ proto bool extension_loaded(string extension_name)
  2321. Returns true if the named extension is loaded */
  2322. ZEND_FUNCTION(extension_loaded)
  2323. {
  2324. zend_string *extension_name;
  2325. zend_string *lcname;
  2326. if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &extension_name) == FAILURE) {
  2327. return;
  2328. }
  2329. lcname = zend_string_tolower(extension_name);
  2330. if (zend_hash_exists(&module_registry, lcname)) {
  2331. RETVAL_TRUE;
  2332. } else {
  2333. RETVAL_FALSE;
  2334. }
  2335. zend_string_release_ex(lcname, 0);
  2336. }
  2337. /* }}} */
  2338. /* {{{ proto array get_extension_funcs(string extension_name)
  2339. Returns an array with the names of functions belonging to the named extension */
  2340. ZEND_FUNCTION(get_extension_funcs)
  2341. {
  2342. zend_string *extension_name;
  2343. zend_string *lcname;
  2344. int array;
  2345. zend_module_entry *module;
  2346. zend_function *zif;
  2347. if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &extension_name) == FAILURE) {
  2348. return;
  2349. }
  2350. if (strncasecmp(ZSTR_VAL(extension_name), "zend", sizeof("zend"))) {
  2351. lcname = zend_string_tolower(extension_name);
  2352. module = zend_hash_find_ptr(&module_registry, lcname);
  2353. zend_string_release_ex(lcname, 0);
  2354. } else {
  2355. module = zend_hash_str_find_ptr(&module_registry, "core", sizeof("core") - 1);
  2356. }
  2357. if (!module) {
  2358. RETURN_FALSE;
  2359. }
  2360. if (module->functions) {
  2361. /* avoid BC break, if functions list is empty, will return an empty array */
  2362. array_init(return_value);
  2363. array = 1;
  2364. } else {
  2365. array = 0;
  2366. }
  2367. ZEND_HASH_FOREACH_PTR(CG(function_table), zif) {
  2368. if (zif->common.type == ZEND_INTERNAL_FUNCTION
  2369. && zif->internal_function.module == module) {
  2370. if (!array) {
  2371. array_init(return_value);
  2372. array = 1;
  2373. }
  2374. add_next_index_str(return_value, zend_string_copy(zif->common.function_name));
  2375. }
  2376. } ZEND_HASH_FOREACH_END();
  2377. if (!array) {
  2378. RETURN_FALSE;
  2379. }
  2380. }
  2381. /* }}} */
  2382. /*
  2383. * Local variables:
  2384. * tab-width: 4
  2385. * c-basic-offset: 4
  2386. * indent-tabs-mode: t
  2387. * End:
  2388. * vim600: sw=4 ts=4 fdm=marker
  2389. * vim<600: sw=4 ts=4
  2390. */