12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296 |
- /*
- +----------------------------------------------------------------------+
- | PHP Version 5 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2016 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 3.01 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available through the world-wide-web at the following url: |
- | http://www.php.net/license/3_01.txt |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Timm Friebe <thekid@thekid.de> |
- | George Schlossnagle <george@omniti.com> |
- | Andrei Zmievski <andrei@gravitonic.com> |
- | Marcus Boerger <helly@php.net> |
- | Johannes Schlueter <johannes@php.net> |
- +----------------------------------------------------------------------+
- */
- /* $Id$ */
- #ifdef HAVE_CONFIG_H
- #include "config.h"
- #endif
- #include "php.h"
- #include "php_ini.h"
- #include "php_reflection.h"
- #include "ext/standard/info.h"
- #include "zend.h"
- #include "zend_API.h"
- #include "zend_exceptions.h"
- #include "zend_operators.h"
- #include "zend_constants.h"
- #include "zend_ini.h"
- #include "zend_interfaces.h"
- #include "zend_closures.h"
- #include "zend_extensions.h"
- #define reflection_update_property(object, name, value) do { \
- zval *member; \
- MAKE_STD_ZVAL(member); \
- ZVAL_STRINGL(member, name, sizeof(name)-1, 1); \
- zend_std_write_property(object, member, value, NULL TSRMLS_CC); \
- Z_DELREF_P(value); \
- zval_ptr_dtor(&member); \
- } while (0)
- /* Class entry pointers */
- PHPAPI zend_class_entry *reflector_ptr;
- PHPAPI zend_class_entry *reflection_exception_ptr;
- PHPAPI zend_class_entry *reflection_ptr;
- PHPAPI zend_class_entry *reflection_function_abstract_ptr;
- PHPAPI zend_class_entry *reflection_function_ptr;
- PHPAPI zend_class_entry *reflection_parameter_ptr;
- PHPAPI zend_class_entry *reflection_class_ptr;
- PHPAPI zend_class_entry *reflection_object_ptr;
- PHPAPI zend_class_entry *reflection_method_ptr;
- PHPAPI zend_class_entry *reflection_property_ptr;
- PHPAPI zend_class_entry *reflection_extension_ptr;
- PHPAPI zend_class_entry *reflection_zend_extension_ptr;
- #if MBO_0
- ZEND_BEGIN_MODULE_GLOBALS(reflection)
- int dummy;
- ZEND_END_MODULE_GLOBALS(reflection)
- #ifdef ZTS
- # define REFLECTION_G(v) \
- TSRMG(reflection_globals_id, zend_reflection_globals*, v)
- extern int reflection_globals_id;
- #else
- # define REFLECTION_G(v) (reflection_globals.v)
- extern zend_reflection_globals reflectionglobals;
- #endif
- ZEND_DECLARE_MODULE_GLOBALS(reflection)
- #endif /* MBO_0 */
- /* Method macros */
- #define METHOD_NOTSTATIC(ce) \
- if (!this_ptr || !instanceof_function(Z_OBJCE_P(this_ptr), ce TSRMLS_CC)) { \
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "%s() cannot be called statically", get_active_function_name(TSRMLS_C)); \
- return; \
- } \
- /* Exception throwing macro */
- #define _DO_THROW(msg) \
- zend_throw_exception(reflection_exception_ptr, msg, 0 TSRMLS_CC); \
- return; \
- #define RETURN_ON_EXCEPTION \
- if (EG(exception) && Z_OBJCE_P(EG(exception)) == reflection_exception_ptr) { \
- return; \
- }
- #define GET_REFLECTION_OBJECT_PTR(target) \
- intern = (reflection_object *) zend_object_store_get_object(getThis() TSRMLS_CC); \
- if (intern == NULL || intern->ptr == NULL) { \
- RETURN_ON_EXCEPTION \
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Failed to retrieve the reflection object"); \
- } \
- target = intern->ptr; \
- /* Class constants */
- #define REGISTER_REFLECTION_CLASS_CONST_LONG(class_name, const_name, value) \
- zend_declare_class_constant_long(reflection_ ## class_name ## _ptr, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC);
- /* {{{ Smart string functions */
- typedef struct _string {
- char *string;
- int len;
- int alloced;
- } string;
- static void string_init(string *str)
- {
- str->string = (char *) emalloc(1024);
- str->len = 1;
- str->alloced = 1024;
- *str->string = '\0';
- }
- static string *string_printf(string *str, const char *format, ...)
- {
- int len;
- va_list arg;
- char *s_tmp;
- va_start(arg, format);
- len = zend_vspprintf(&s_tmp, 0, format, arg);
- if (len) {
- register int nlen = (str->len + len + (1024 - 1)) & ~(1024 - 1);
- if (str->alloced < nlen) {
- str->alloced = nlen;
- str->string = erealloc(str->string, str->alloced);
- }
- memcpy(str->string + str->len - 1, s_tmp, len + 1);
- str->len += len;
- }
- efree(s_tmp);
- va_end(arg);
- return str;
- }
- static string *string_write(string *str, char *buf, int len)
- {
- register int nlen = (str->len + len + (1024 - 1)) & ~(1024 - 1);
- if (str->alloced < nlen) {
- str->alloced = nlen;
- str->string = erealloc(str->string, str->alloced);
- }
- memcpy(str->string + str->len - 1, buf, len);
- str->len += len;
- str->string[str->len - 1] = '\0';
- return str;
- }
- static string *string_append(string *str, string *append)
- {
- if (append->len > 1) {
- string_write(str, append->string, append->len - 1);
- }
- return str;
- }
- static void string_free(string *str)
- {
- efree(str->string);
- str->len = 0;
- str->alloced = 0;
- str->string = NULL;
- }
- /* }}} */
- /* {{{ Object structure */
- /* Struct for properties */
- typedef struct _property_reference {
- zend_class_entry *ce;
- zend_property_info prop;
- } property_reference;
- /* Struct for parameters */
- typedef struct _parameter_reference {
- zend_uint offset;
- zend_uint required;
- struct _zend_arg_info *arg_info;
- zend_function *fptr;
- } parameter_reference;
- typedef enum {
- REF_TYPE_OTHER, /* Must be 0 */
- REF_TYPE_FUNCTION,
- REF_TYPE_PARAMETER,
- REF_TYPE_PROPERTY,
- REF_TYPE_DYNAMIC_PROPERTY
- } reflection_type_t;
- /* Struct for reflection objects */
- typedef struct {
- zend_object zo;
- void *ptr;
- reflection_type_t ref_type;
- zval *obj;
- zend_class_entry *ce;
- unsigned int ignore_visibility:1;
- } reflection_object;
- /* }}} */
- static zend_object_handlers reflection_object_handlers;
- static void _default_get_entry(zval *object, char *name, int name_len, zval *return_value TSRMLS_DC) /* {{{ */
- {
- zval **value;
- if (zend_hash_find(Z_OBJPROP_P(object), name, name_len, (void **) &value) == FAILURE) {
- RETURN_FALSE;
- }
- MAKE_COPY_ZVAL(value, return_value);
- }
- /* }}} */
- #ifdef ilia_0
- static void _default_lookup_entry(zval *object, char *name, int name_len, zval **return_value TSRMLS_DC) /* {{{ */
- {
- zval **value;
- if (zend_hash_find(Z_OBJPROP_P(object), name, name_len, (void **) &value) == FAILURE) {
- *return_value = NULL;
- } else {
- *return_value = *value;
- }
- }
- /* }}} */
- #endif
- static void reflection_zval_deep_copy(zval **p)
- {
- zval *value;
- ALLOC_ZVAL(value);
- *value = **p;
- if (Z_TYPE_P(value) == IS_ARRAY) {
- HashTable *ht;
- ALLOC_HASHTABLE(ht);
- zend_hash_init(ht, zend_hash_num_elements(Z_ARRVAL_P(value)), NULL, ZVAL_PTR_DTOR, 0);
- zend_hash_copy(ht, Z_ARRVAL_P(value), (copy_ctor_func_t) reflection_zval_deep_copy, NULL, sizeof(zval *));
- Z_ARRVAL_P(value) = ht;
- } else {
- zval_copy_ctor(value);
- }
- INIT_PZVAL(value);
- *p = value;
- }
- static void reflection_register_implement(zend_class_entry *class_entry, zend_class_entry *interface_entry TSRMLS_DC) /* {{{ */
- {
- zend_uint num_interfaces = ++class_entry->num_interfaces;
- class_entry->interfaces = (zend_class_entry **) realloc(class_entry->interfaces, sizeof(zend_class_entry *) * num_interfaces);
- class_entry->interfaces[num_interfaces - 1] = interface_entry;
- }
- /* }}} */
- static zend_function *_copy_function(zend_function *fptr TSRMLS_DC) /* {{{ */
- {
- if (fptr
- && fptr->type == ZEND_INTERNAL_FUNCTION
- && (fptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0)
- {
- zend_function *copy_fptr;
- copy_fptr = emalloc(sizeof(zend_function));
- memcpy(copy_fptr, fptr, sizeof(zend_function));
- copy_fptr->internal_function.function_name = estrdup(fptr->internal_function.function_name);
- return copy_fptr;
- } else {
- /* no copy needed */
- return fptr;
- }
- }
- /* }}} */
- static void _free_function(zend_function *fptr TSRMLS_DC) /* {{{ */
- {
- if (fptr
- && fptr->type == ZEND_INTERNAL_FUNCTION
- && (fptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0)
- {
- efree((char*)fptr->internal_function.function_name);
- efree(fptr);
- }
- }
- /* }}} */
- static void reflection_free_objects_storage(void *object TSRMLS_DC) /* {{{ */
- {
- reflection_object *intern = (reflection_object *) object;
- parameter_reference *reference;
- property_reference *prop_reference;
- if (intern->ptr) {
- switch (intern->ref_type) {
- case REF_TYPE_PARAMETER:
- reference = (parameter_reference*)intern->ptr;
- _free_function(reference->fptr TSRMLS_CC);
- efree(intern->ptr);
- break;
- case REF_TYPE_FUNCTION:
- _free_function(intern->ptr TSRMLS_CC);
- break;
- case REF_TYPE_PROPERTY:
- efree(intern->ptr);
- break;
- case REF_TYPE_DYNAMIC_PROPERTY:
- prop_reference = (property_reference*)intern->ptr;
- efree((char*)prop_reference->prop.name);
- efree(intern->ptr);
- break;
- case REF_TYPE_OTHER:
- break;
- }
- }
- intern->ptr = NULL;
- if (intern->obj) {
- zval_ptr_dtor(&intern->obj);
- }
- zend_objects_free_object_storage(object TSRMLS_CC);
- }
- /* }}} */
- static zend_object_value reflection_objects_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
- {
- zend_object_value retval;
- reflection_object *intern;
- intern = ecalloc(1, sizeof(reflection_object));
- intern->zo.ce = class_type;
- zend_object_std_init(&intern->zo, class_type TSRMLS_CC);
- object_properties_init(&intern->zo, class_type);
- retval.handle = zend_objects_store_put(intern, NULL, reflection_free_objects_storage, NULL TSRMLS_CC);
- retval.handlers = &reflection_object_handlers;
- return retval;
- }
- /* }}} */
- static zval * reflection_instantiate(zend_class_entry *pce, zval *object TSRMLS_DC) /* {{{ */
- {
- if (!object) {
- ALLOC_ZVAL(object);
- }
- Z_TYPE_P(object) = IS_OBJECT;
- object_init_ex(object, pce);
- Z_SET_REFCOUNT_P(object, 1);
- Z_SET_ISREF_P(object);
- return object;
- }
- /* }}} */
- static void _const_string(string *str, char *name, zval *value, char *indent TSRMLS_DC);
- static void _function_string(string *str, zend_function *fptr, zend_class_entry *scope, char* indent TSRMLS_DC);
- static void _property_string(string *str, zend_property_info *prop, char *prop_name, char* indent TSRMLS_DC);
- static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *indent TSRMLS_DC);
- static void _extension_string(string *str, zend_module_entry *module, char *indent TSRMLS_DC);
- static void _zend_extension_string(string *str, zend_extension *extension, char *indent TSRMLS_DC);
- /* {{{ _class_string */
- static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *indent TSRMLS_DC)
- {
- int count, count_static_props = 0, count_static_funcs = 0, count_shadow_props = 0;
- string sub_indent;
- string_init(&sub_indent);
- string_printf(&sub_indent, "%s ", indent);
- /* TBD: Repair indenting of doc comment (or is this to be done in the parser?) */
- if (ce->type == ZEND_USER_CLASS && ce->info.user.doc_comment) {
- string_printf(str, "%s%s", indent, ce->info.user.doc_comment);
- string_write(str, "\n", 1);
- }
- if (obj) {
- string_printf(str, "%sObject of class [ ", indent);
- } else {
- char *kind = "Class";
- if (ce->ce_flags & ZEND_ACC_INTERFACE) {
- kind = "Interface";
- } else if ((ce->ce_flags & ZEND_ACC_TRAIT) == ZEND_ACC_TRAIT) {
- kind = "Trait";
- }
- string_printf(str, "%s%s [ ", indent, kind);
- }
- string_printf(str, (ce->type == ZEND_USER_CLASS) ? "<user" : "<internal");
- if (ce->type == ZEND_INTERNAL_CLASS && ce->info.internal.module) {
- string_printf(str, ":%s", ce->info.internal.module->name);
- }
- string_printf(str, "> ");
- if (ce->get_iterator != NULL) {
- string_printf(str, "<iterateable> ");
- }
- if (ce->ce_flags & ZEND_ACC_INTERFACE) {
- string_printf(str, "interface ");
- } else if ((ce->ce_flags & ZEND_ACC_TRAIT) == ZEND_ACC_TRAIT) {
- string_printf(str, "trait ");
- } else {
- if (ce->ce_flags & (ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) {
- string_printf(str, "abstract ");
- }
- if (ce->ce_flags & ZEND_ACC_FINAL_CLASS) {
- string_printf(str, "final ");
- }
- string_printf(str, "class ");
- }
- string_printf(str, "%s", ce->name);
- if (ce->parent) {
- string_printf(str, " extends %s", ce->parent->name);
- }
- if (ce->num_interfaces) {
- zend_uint i;
- if (ce->ce_flags & ZEND_ACC_INTERFACE) {
- string_printf(str, " extends %s", ce->interfaces[0]->name);
- } else {
- string_printf(str, " implements %s", ce->interfaces[0]->name);
- }
- for (i = 1; i < ce->num_interfaces; ++i) {
- string_printf(str, ", %s", ce->interfaces[i]->name);
- }
- }
- string_printf(str, " ] {\n");
- /* The information where a class is declared is only available for user classes */
- if (ce->type == ZEND_USER_CLASS) {
- string_printf(str, "%s @@ %s %d-%d\n", indent, ce->info.user.filename,
- ce->info.user.line_start, ce->info.user.line_end);
- }
- /* Constants */
- if (&ce->constants_table) {
- zend_hash_apply_with_argument(&ce->constants_table, (apply_func_arg_t) zval_update_constant, (void*)1 TSRMLS_CC);
- string_printf(str, "\n");
- count = zend_hash_num_elements(&ce->constants_table);
- string_printf(str, "%s - Constants [%d] {\n", indent, count);
- if (count > 0) {
- HashPosition pos;
- zval **value;
- char *key;
- uint key_len;
- ulong num_index;
- zend_hash_internal_pointer_reset_ex(&ce->constants_table, &pos);
- while (zend_hash_get_current_data_ex(&ce->constants_table, (void **) &value, &pos) == SUCCESS) {
- zend_hash_get_current_key_ex(&ce->constants_table, &key, &key_len, &num_index, 0, &pos);
- _const_string(str, key, *value, indent TSRMLS_CC);
- zend_hash_move_forward_ex(&ce->constants_table, &pos);
- }
- }
- string_printf(str, "%s }\n", indent);
- }
- /* Static properties */
- if (&ce->properties_info) {
- /* counting static properties */
- count = zend_hash_num_elements(&ce->properties_info);
- if (count > 0) {
- HashPosition pos;
- zend_property_info *prop;
- zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos);
- while (zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop, &pos) == SUCCESS) {
- if(prop->flags & ZEND_ACC_SHADOW) {
- count_shadow_props++;
- } else if (prop->flags & ZEND_ACC_STATIC) {
- count_static_props++;
- }
- zend_hash_move_forward_ex(&ce->properties_info, &pos);
- }
- }
- /* static properties */
- string_printf(str, "\n%s - Static properties [%d] {\n", indent, count_static_props);
- if (count_static_props > 0) {
- HashPosition pos;
- zend_property_info *prop;
- zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos);
- while (zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop, &pos) == SUCCESS) {
- if ((prop->flags & ZEND_ACC_STATIC) && !(prop->flags & ZEND_ACC_SHADOW)) {
- _property_string(str, prop, NULL, sub_indent.string TSRMLS_CC);
- }
- zend_hash_move_forward_ex(&ce->properties_info, &pos);
- }
- }
- string_printf(str, "%s }\n", indent);
- }
- /* Static methods */
- if (&ce->function_table) {
- /* counting static methods */
- count = zend_hash_num_elements(&ce->function_table);
- if (count > 0) {
- HashPosition pos;
- zend_function *mptr;
- zend_hash_internal_pointer_reset_ex(&ce->function_table, &pos);
- while (zend_hash_get_current_data_ex(&ce->function_table, (void **) &mptr, &pos) == SUCCESS) {
- if (mptr->common.fn_flags & ZEND_ACC_STATIC
- && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce))
- {
- count_static_funcs++;
- }
- zend_hash_move_forward_ex(&ce->function_table, &pos);
- }
- }
- /* static methods */
- string_printf(str, "\n%s - Static methods [%d] {", indent, count_static_funcs);
- if (count_static_funcs > 0) {
- HashPosition pos;
- zend_function *mptr;
- zend_hash_internal_pointer_reset_ex(&ce->function_table, &pos);
- while (zend_hash_get_current_data_ex(&ce->function_table, (void **) &mptr, &pos) == SUCCESS) {
- if (mptr->common.fn_flags & ZEND_ACC_STATIC
- && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce))
- {
- string_printf(str, "\n");
- _function_string(str, mptr, ce, sub_indent.string TSRMLS_CC);
- }
- zend_hash_move_forward_ex(&ce->function_table, &pos);
- }
- } else {
- string_printf(str, "\n");
- }
- string_printf(str, "%s }\n", indent);
- }
- /* Default/Implicit properties */
- if (&ce->properties_info) {
- count = zend_hash_num_elements(&ce->properties_info) - count_static_props - count_shadow_props;
- string_printf(str, "\n%s - Properties [%d] {\n", indent, count);
- if (count > 0) {
- HashPosition pos;
- zend_property_info *prop;
- zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos);
- while (zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop, &pos) == SUCCESS) {
- if (!(prop->flags & (ZEND_ACC_STATIC|ZEND_ACC_SHADOW))) {
- _property_string(str, prop, NULL, sub_indent.string TSRMLS_CC);
- }
- zend_hash_move_forward_ex(&ce->properties_info, &pos);
- }
- }
- string_printf(str, "%s }\n", indent);
- }
- if (obj && Z_OBJ_HT_P(obj)->get_properties) {
- string dyn;
- HashTable *properties = Z_OBJ_HT_P(obj)->get_properties(obj TSRMLS_CC);
- HashPosition pos;
- zval **prop;
- string_init(&dyn);
- count = 0;
- if (properties && zend_hash_num_elements(properties)) {
- zend_hash_internal_pointer_reset_ex(properties, &pos);
- while (zend_hash_get_current_data_ex(properties, (void **) &prop, &pos) == SUCCESS) {
- char *prop_name;
- uint prop_name_size;
- ulong index;
- if (zend_hash_get_current_key_ex(properties, &prop_name, &prop_name_size, &index, 1, &pos) == HASH_KEY_IS_STRING) {
- if (prop_name_size && prop_name[0]) { /* skip all private and protected properties */
- if (!zend_hash_quick_exists(&ce->properties_info, prop_name, prop_name_size, zend_get_hash_value(prop_name, prop_name_size))) {
- count++;
- _property_string(&dyn, NULL, prop_name, sub_indent.string TSRMLS_CC);
- }
- }
- efree(prop_name);
- }
- zend_hash_move_forward_ex(properties, &pos);
- }
- }
- string_printf(str, "\n%s - Dynamic properties [%d] {\n", indent, count);
- string_append(str, &dyn);
- string_printf(str, "%s }\n", indent);
- string_free(&dyn);
- }
- /* Non static methods */
- if (&ce->function_table) {
- count = zend_hash_num_elements(&ce->function_table) - count_static_funcs;
- if (count > 0) {
- HashPosition pos;
- zend_function *mptr;
- string dyn;
- count = 0;
- string_init(&dyn);
- zend_hash_internal_pointer_reset_ex(&ce->function_table, &pos);
- while (zend_hash_get_current_data_ex(&ce->function_table, (void **) &mptr, &pos) == SUCCESS) {
- if ((mptr->common.fn_flags & ZEND_ACC_STATIC) == 0
- && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce))
- {
- char *key;
- uint key_len;
- ulong num_index;
- uint len = strlen(mptr->common.function_name);
- /* Do not display old-style inherited constructors */
- if ((mptr->common.fn_flags & ZEND_ACC_CTOR) == 0
- || mptr->common.scope == ce
- || zend_hash_get_current_key_ex(&ce->function_table, &key, &key_len, &num_index, 0, &pos) != HASH_KEY_IS_STRING
- || zend_binary_strcasecmp(key, key_len-1, mptr->common.function_name, len) == 0)
- {
- zend_function *closure;
- /* see if this is a closure */
- if (ce == zend_ce_closure && obj && (len == sizeof(ZEND_INVOKE_FUNC_NAME)-1)
- && memcmp(mptr->common.function_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0
- && (closure = zend_get_closure_invoke_method(obj TSRMLS_CC)) != NULL)
- {
- mptr = closure;
- } else {
- closure = NULL;
- }
- string_printf(&dyn, "\n");
- _function_string(&dyn, mptr, ce, sub_indent.string TSRMLS_CC);
- count++;
- _free_function(closure TSRMLS_CC);
- }
- }
- zend_hash_move_forward_ex(&ce->function_table, &pos);
- }
- string_printf(str, "\n%s - Methods [%d] {", indent, count);
- if (!count) {
- string_printf(str, "\n");
- }
- string_append(str, &dyn);
- string_free(&dyn);
- } else {
- string_printf(str, "\n%s - Methods [0] {\n", indent);
- }
- string_printf(str, "%s }\n", indent);
- }
- string_printf(str, "%s}\n", indent);
- string_free(&sub_indent);
- }
- /* }}} */
- /* {{{ _const_string */
- static void _const_string(string *str, char *name, zval *value, char *indent TSRMLS_DC)
- {
- char *type;
- type = zend_zval_type_name(value);
- if (Z_TYPE_P(value) == IS_ARRAY) {
- string_printf(str, "%s Constant [ %s %s ] { Array }\n",
- indent, type, name);
- } else {
- zval value_copy;
- int use_copy;
- zend_make_printable_zval(value, &value_copy, &use_copy);
- if (use_copy) {
- value = &value_copy;
- }
- string_printf(str, "%s Constant [ %s %s ] { %s }\n",
- indent, type, name, Z_STRVAL_P(value));
- if (use_copy) {
- zval_dtor(value);
- }
- }
- }
- /* }}} */
- /* {{{ _get_recv_opcode */
- static zend_op* _get_recv_op(zend_op_array *op_array, zend_uint offset)
- {
- zend_op *op = op_array->opcodes;
- zend_op *end = op + op_array->last;
- ++offset;
- while (op < end) {
- if ((op->opcode == ZEND_RECV || op->opcode == ZEND_RECV_INIT
- || op->opcode == ZEND_RECV_VARIADIC) && op->op1.num == (long)offset)
- {
- return op;
- }
- ++op;
- }
- return NULL;
- }
- /* }}} */
- /* {{{ _parameter_string */
- static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg_info *arg_info, zend_uint offset, zend_uint required, char* indent TSRMLS_DC)
- {
- string_printf(str, "Parameter #%d [ ", offset);
- if (offset >= required) {
- string_printf(str, "<optional> ");
- } else {
- string_printf(str, "<required> ");
- }
- if (arg_info->class_name) {
- string_printf(str, "%s ", arg_info->class_name);
- if (arg_info->allow_null) {
- string_printf(str, "or NULL ");
- }
- } else if (arg_info->type_hint) {
- string_printf(str, "%s ", zend_get_type_by_const(arg_info->type_hint));
- if (arg_info->allow_null) {
- string_printf(str, "or NULL ");
- }
- }
- if (arg_info->pass_by_reference) {
- string_write(str, "&", sizeof("&")-1);
- }
- if (arg_info->is_variadic) {
- string_write(str, "...", sizeof("...")-1);
- }
- if (arg_info->name) {
- string_printf(str, "$%s", arg_info->name);
- } else {
- string_printf(str, "$param%d", offset);
- }
- if (fptr->type == ZEND_USER_FUNCTION && offset >= required) {
- zend_op *precv = _get_recv_op((zend_op_array*)fptr, offset);
- if (precv && precv->opcode == ZEND_RECV_INIT && precv->op2_type != IS_UNUSED) {
- zval *zv, zv_copy;
- int use_copy;
- zend_class_entry *old_scope;
- string_write(str, " = ", sizeof(" = ")-1);
- if (IS_CONSTANT_TYPE(Z_TYPE_P(precv->op2.zv))) {
- ALLOC_ZVAL(zv);
- *zv = *precv->op2.zv;
- zval_copy_ctor(zv);
- INIT_PZVAL(zv);
- old_scope = EG(scope);
- EG(scope) = fptr->common.scope;
- zval_update_constant_ex(&zv, 1, NULL TSRMLS_CC);
- EG(scope) = old_scope;
- } else {
- zv = precv->op2.zv;
- }
- if (Z_TYPE_P(zv) == IS_BOOL) {
- if (Z_LVAL_P(zv)) {
- string_write(str, "true", sizeof("true")-1);
- } else {
- string_write(str, "false", sizeof("false")-1);
- }
- } else if (Z_TYPE_P(zv) == IS_NULL) {
- string_write(str, "NULL", sizeof("NULL")-1);
- } else if (Z_TYPE_P(zv) == IS_STRING) {
- string_write(str, "'", sizeof("'")-1);
- string_write(str, Z_STRVAL_P(zv), MIN(Z_STRLEN_P(zv), 15));
- if (Z_STRLEN_P(zv) > 15) {
- string_write(str, "...", sizeof("...")-1);
- }
- string_write(str, "'", sizeof("'")-1);
- } else if (Z_TYPE_P(zv) == IS_ARRAY) {
- string_write(str, "Array", sizeof("Array")-1);
- } else {
- zend_make_printable_zval(zv, &zv_copy, &use_copy);
- string_write(str, Z_STRVAL(zv_copy), Z_STRLEN(zv_copy));
- if (use_copy) {
- zval_dtor(&zv_copy);
- }
- }
- if (zv != precv->op2.zv) {
- zval_ptr_dtor(&zv);
- }
- }
- }
- string_write(str, " ]", sizeof(" ]")-1);
- }
- /* }}} */
- /* {{{ _function_parameter_string */
- static void _function_parameter_string(string *str, zend_function *fptr, char* indent TSRMLS_DC)
- {
- struct _zend_arg_info *arg_info = fptr->common.arg_info;
- zend_uint i, required = fptr->common.required_num_args;
- if (!arg_info) {
- return;
- }
- string_printf(str, "\n");
- string_printf(str, "%s- Parameters [%d] {\n", indent, fptr->common.num_args);
- for (i = 0; i < fptr->common.num_args; i++) {
- string_printf(str, "%s ", indent);
- _parameter_string(str, fptr, arg_info, i, required, indent TSRMLS_CC);
- string_write(str, "\n", sizeof("\n")-1);
- arg_info++;
- }
- string_printf(str, "%s}\n", indent);
- }
- /* }}} */
- /* {{{ _function_closure_string */
- static void _function_closure_string(string *str, zend_function *fptr, char* indent TSRMLS_DC)
- {
- zend_uint i, count;
- ulong num_index;
- char *key;
- uint key_len;
- HashTable *static_variables;
- HashPosition pos;
- if (fptr->type != ZEND_USER_FUNCTION || !fptr->op_array.static_variables) {
- return;
- }
- static_variables = fptr->op_array.static_variables;
- count = zend_hash_num_elements(static_variables);
- if (!count) {
- return;
- }
- string_printf(str, "\n");
- string_printf(str, "%s- Bound Variables [%d] {\n", indent, zend_hash_num_elements(static_variables));
- zend_hash_internal_pointer_reset_ex(static_variables, &pos);
- i = 0;
- while (i < count) {
- zend_hash_get_current_key_ex(static_variables, &key, &key_len, &num_index, 0, &pos);
- string_printf(str, "%s Variable #%d [ $%s ]\n", indent, i++, key);
- zend_hash_move_forward_ex(static_variables, &pos);
- }
- string_printf(str, "%s}\n", indent);
- }
- /* }}} */
- /* {{{ _function_string */
- static void _function_string(string *str, zend_function *fptr, zend_class_entry *scope, char* indent TSRMLS_DC)
- {
- string param_indent;
- zend_function *overwrites;
- char *lc_name;
- unsigned int lc_name_len;
- /* TBD: Repair indenting of doc comment (or is this to be done in the parser?)
- * What's "wrong" is that any whitespace before the doc comment start is
- * swallowed, leading to an unaligned comment.
- */
- if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.doc_comment) {
- string_printf(str, "%s%s\n", indent, fptr->op_array.doc_comment);
- }
- string_write(str, indent, strlen(indent));
- string_printf(str, fptr->common.fn_flags & ZEND_ACC_CLOSURE ? "Closure [ " : (fptr->common.scope ? "Method [ " : "Function [ "));
- string_printf(str, (fptr->type == ZEND_USER_FUNCTION) ? "<user" : "<internal");
- if (fptr->common.fn_flags & ZEND_ACC_DEPRECATED) {
- string_printf(str, ", deprecated");
- }
- if (fptr->type == ZEND_INTERNAL_FUNCTION && ((zend_internal_function*)fptr)->module) {
- string_printf(str, ":%s", ((zend_internal_function*)fptr)->module->name);
- }
- if (scope && fptr->common.scope) {
- if (fptr->common.scope != scope) {
- string_printf(str, ", inherits %s", fptr->common.scope->name);
- } else if (fptr->common.scope->parent) {
- lc_name_len = strlen(fptr->common.function_name);
- lc_name = zend_str_tolower_dup(fptr->common.function_name, lc_name_len);
- if (zend_hash_find(&fptr->common.scope->parent->function_table, lc_name, lc_name_len + 1, (void**) &overwrites) == SUCCESS) {
- if (fptr->common.scope != overwrites->common.scope) {
- string_printf(str, ", overwrites %s", overwrites->common.scope->name);
- }
- }
- efree(lc_name);
- }
- }
- if (fptr->common.prototype && fptr->common.prototype->common.scope) {
- string_printf(str, ", prototype %s", fptr->common.prototype->common.scope->name);
- }
- if (fptr->common.fn_flags & ZEND_ACC_CTOR) {
- string_printf(str, ", ctor");
- }
- if (fptr->common.fn_flags & ZEND_ACC_DTOR) {
- string_printf(str, ", dtor");
- }
- string_printf(str, "> ");
- if (fptr->common.fn_flags & ZEND_ACC_ABSTRACT) {
- string_printf(str, "abstract ");
- }
- if (fptr->common.fn_flags & ZEND_ACC_FINAL) {
- string_printf(str, "final ");
- }
- if (fptr->common.fn_flags & ZEND_ACC_STATIC) {
- string_printf(str, "static ");
- }
- if (fptr->common.scope) {
- /* These are mutually exclusive */
- switch (fptr->common.fn_flags & ZEND_ACC_PPP_MASK) {
- case ZEND_ACC_PUBLIC:
- string_printf(str, "public ");
- break;
- case ZEND_ACC_PRIVATE:
- string_printf(str, "private ");
- break;
- case ZEND_ACC_PROTECTED:
- string_printf(str, "protected ");
- break;
- default:
- string_printf(str, "<visibility error> ");
- break;
- }
- string_printf(str, "method ");
- } else {
- string_printf(str, "function ");
- }
- if (fptr->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE) {
- string_printf(str, "&");
- }
- string_printf(str, "%s ] {\n", fptr->common.function_name);
- /* The information where a function is declared is only available for user classes */
- if (fptr->type == ZEND_USER_FUNCTION) {
- string_printf(str, "%s @@ %s %d - %d\n", indent,
- fptr->op_array.filename,
- fptr->op_array.line_start,
- fptr->op_array.line_end);
- }
- string_init(¶m_indent);
- string_printf(¶m_indent, "%s ", indent);
- if (fptr->common.fn_flags & ZEND_ACC_CLOSURE) {
- _function_closure_string(str, fptr, param_indent.string TSRMLS_CC);
- }
- _function_parameter_string(str, fptr, param_indent.string TSRMLS_CC);
- string_free(¶m_indent);
- string_printf(str, "%s}\n", indent);
- }
- /* }}} */
- /* {{{ _property_string */
- static void _property_string(string *str, zend_property_info *prop, char *prop_name, char* indent TSRMLS_DC)
- {
- const char *class_name;
- string_printf(str, "%sProperty [ ", indent);
- if (!prop) {
- string_printf(str, "<dynamic> public $%s", prop_name);
- } else {
- if (!(prop->flags & ZEND_ACC_STATIC)) {
- if (prop->flags & ZEND_ACC_IMPLICIT_PUBLIC) {
- string_write(str, "<implicit> ", sizeof("<implicit> ") - 1);
- } else {
- string_write(str, "<default> ", sizeof("<default> ") - 1);
- }
- }
- /* These are mutually exclusive */
- switch (prop->flags & ZEND_ACC_PPP_MASK) {
- case ZEND_ACC_PUBLIC:
- string_printf(str, "public ");
- break;
- case ZEND_ACC_PRIVATE:
- string_printf(str, "private ");
- break;
- case ZEND_ACC_PROTECTED:
- string_printf(str, "protected ");
- break;
- }
- if(prop->flags & ZEND_ACC_STATIC) {
- string_printf(str, "static ");
- }
- zend_unmangle_property_name(prop->name, prop->name_length, &class_name, (const char**)&prop_name);
- string_printf(str, "$%s", prop_name);
- }
- string_printf(str, " ]\n");
- }
- /* }}} */
- static int _extension_ini_string(zend_ini_entry *ini_entry TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
- {
- string *str = va_arg(args, string *);
- char *indent = va_arg(args, char *);
- int number = va_arg(args, int);
- char *comma = "";
- if (number == ini_entry->module_number) {
- string_printf(str, " %sEntry [ %s <", indent, ini_entry->name);
- if (ini_entry->modifiable == ZEND_INI_ALL) {
- string_printf(str, "ALL");
- } else {
- if (ini_entry->modifiable & ZEND_INI_USER) {
- string_printf(str, "USER");
- comma = ",";
- }
- if (ini_entry->modifiable & ZEND_INI_PERDIR) {
- string_printf(str, "%sPERDIR", comma);
- comma = ",";
- }
- if (ini_entry->modifiable & ZEND_INI_SYSTEM) {
- string_printf(str, "%sSYSTEM", comma);
- }
- }
- string_printf(str, "> ]\n");
- string_printf(str, " %s Current = '%s'\n", indent, ini_entry->value ? ini_entry->value : "");
- if (ini_entry->modified) {
- string_printf(str, " %s Default = '%s'\n", indent, ini_entry->orig_value ? ini_entry->orig_value : "");
- }
- string_printf(str, " %s}\n", indent);
- }
- return ZEND_HASH_APPLY_KEEP;
- }
- /* }}} */
- static int _extension_class_string(zend_class_entry **pce TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
- {
- string *str = va_arg(args, string *);
- char *indent = va_arg(args, char *);
- struct _zend_module_entry *module = va_arg(args, struct _zend_module_entry*);
- int *num_classes = va_arg(args, int*);
- if (((*pce)->type == ZEND_INTERNAL_CLASS) && (*pce)->info.internal.module && !strcasecmp((*pce)->info.internal.module->name, module->name)) {
- /* dump class if it is not an alias */
- if (!zend_binary_strcasecmp((*pce)->name, (*pce)->name_length, hash_key->arKey, hash_key->nKeyLength-1)) {
- string_printf(str, "\n");
- _class_string(str, *pce, NULL, indent TSRMLS_CC);
- (*num_classes)++;
- }
- }
- return ZEND_HASH_APPLY_KEEP;
- }
- /* }}} */
- static int _extension_const_string(zend_constant *constant TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
- {
- string *str = va_arg(args, string *);
- char *indent = va_arg(args, char *);
- struct _zend_module_entry *module = va_arg(args, struct _zend_module_entry*);
- int *num_classes = va_arg(args, int*);
- if (constant->module_number == module->module_number) {
- _const_string(str, constant->name, &constant->value, indent TSRMLS_CC);
- (*num_classes)++;
- }
- return ZEND_HASH_APPLY_KEEP;
- }
- /* }}} */
- /* {{{ _extension_string */
- static void _extension_string(string *str, zend_module_entry *module, char *indent TSRMLS_DC)
- {
- string_printf(str, "%sExtension [ ", indent);
- if (module->type == MODULE_PERSISTENT) {
- string_printf(str, "<persistent>");
- }
- if (module->type == MODULE_TEMPORARY) {
- string_printf(str, "<temporary>" );
- }
- string_printf(str, " extension #%d %s version %s ] {\n",
- module->module_number, module->name,
- (module->version == NO_VERSION_YET) ? "<no_version>" : module->version);
- if (module->deps) {
- const zend_module_dep* dep = module->deps;
- string_printf(str, "\n - Dependencies {\n");
- while(dep->name) {
- string_printf(str, "%s Dependency [ %s (", indent, dep->name);
- switch(dep->type) {
- case MODULE_DEP_REQUIRED:
- string_write(str, "Required", sizeof("Required") - 1);
- break;
- case MODULE_DEP_CONFLICTS:
- string_write(str, "Conflicts", sizeof("Conflicts") - 1);
- break;
- case MODULE_DEP_OPTIONAL:
- string_write(str, "Optional", sizeof("Optional") - 1);
- break;
- default:
- string_write(str, "Error", sizeof("Error") - 1); /* shouldn't happen */
- break;
- }
- if (dep->rel) {
- string_printf(str, " %s", dep->rel);
- }
- if (dep->version) {
- string_printf(str, " %s", dep->version);
- }
- string_write(str, ") ]\n", sizeof(") ]\n") - 1);
- dep++;
- }
- string_printf(str, "%s }\n", indent);
- }
- {
- string str_ini;
- string_init(&str_ini);
- zend_hash_apply_with_arguments(EG(ini_directives) TSRMLS_CC, (apply_func_args_t) _extension_ini_string, 3, &str_ini, indent, module->module_number);
- if (str_ini.len > 1) {
- string_printf(str, "\n - INI {\n");
- string_append(str, &str_ini);
- string_printf(str, "%s }\n", indent);
- }
- string_free(&str_ini);
- }
- {
- string str_constants;
- int num_constants = 0;
- string_init(&str_constants);
- zend_hash_apply_with_arguments(EG(zend_constants) TSRMLS_CC, (apply_func_args_t) _extension_const_string, 4, &str_constants, indent, module, &num_constants);
- if (num_constants) {
- string_printf(str, "\n - Constants [%d] {\n", num_constants);
- string_append(str, &str_constants);
- string_printf(str, "%s }\n", indent);
- }
- string_free(&str_constants);
- }
- {
- HashPosition iterator;
- zend_function *fptr;
- int first = 1;
- zend_hash_internal_pointer_reset_ex(CG(function_table), &iterator);
- while (zend_hash_get_current_data_ex(CG(function_table), (void **) &fptr, &iterator) == SUCCESS) {
- if (fptr->common.type==ZEND_INTERNAL_FUNCTION
- && fptr->internal_function.module == module) {
- if (first) {
- string_printf(str, "\n - Functions {\n");
- first = 0;
- }
- _function_string(str, fptr, NULL, " " TSRMLS_CC);
- }
- zend_hash_move_forward_ex(CG(function_table), &iterator);
- }
- if (!first) {
- string_printf(str, "%s }\n", indent);
- }
- }
- {
- string str_classes;
- string sub_indent;
- int num_classes = 0;
- string_init(&sub_indent);
- string_printf(&sub_indent, "%s ", indent);
- string_init(&str_classes);
- zend_hash_apply_with_arguments(EG(class_table) TSRMLS_CC, (apply_func_args_t) _extension_class_string, 4, &str_classes, sub_indent.string, module, &num_classes);
- if (num_classes) {
- string_printf(str, "\n - Classes [%d] {", num_classes);
- string_append(str, &str_classes);
- string_printf(str, "%s }\n", indent);
- }
- string_free(&str_classes);
- string_free(&sub_indent);
- }
- string_printf(str, "%s}\n", indent);
- }
- /* }}} */
- static void _zend_extension_string(string *str, zend_extension *extension, char *indent TSRMLS_DC) /* {{{ */
- {
- string_printf(str, "%sZend Extension [ %s ", indent, extension->name);
- if (extension->version) {
- string_printf(str, "%s ", extension->version);
- }
- if (extension->copyright) {
- string_printf(str, "%s ", extension->copyright);
- }
- if (extension->author) {
- string_printf(str, "by %s ", extension->author);
- }
- if (extension->URL) {
- string_printf(str, "<%s> ", extension->URL);
- }
- string_printf(str, "]\n");
- }
- /* }}} */
- /* {{{ _function_check_flag */
- static void _function_check_flag(INTERNAL_FUNCTION_PARAMETERS, int mask)
- {
- reflection_object *intern;
- zend_function *mptr;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(mptr);
- RETURN_BOOL(mptr->common.fn_flags & mask);
- }
- /* }}} */
- /* {{{ zend_reflection_class_factory */
- PHPAPI void zend_reflection_class_factory(zend_class_entry *ce, zval *object TSRMLS_DC)
- {
- reflection_object *intern;
- zval *name;
- MAKE_STD_ZVAL(name);
- ZVAL_STRINGL(name, ce->name, ce->name_length, 1);
- reflection_instantiate(reflection_class_ptr, object TSRMLS_CC);
- intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC);
- intern->ptr = ce;
- intern->ref_type = REF_TYPE_OTHER;
- intern->ce = ce;
- reflection_update_property(object, "name", name);
- }
- /* }}} */
- /* {{{ reflection_extension_factory */
- static void reflection_extension_factory(zval *object, const char *name_str TSRMLS_DC)
- {
- reflection_object *intern;
- zval *name;
- int name_len = strlen(name_str);
- char *lcname;
- struct _zend_module_entry *module;
- ALLOCA_FLAG(use_heap)
- lcname = do_alloca(name_len + 1, use_heap);
- zend_str_tolower_copy(lcname, name_str, name_len);
- if (zend_hash_find(&module_registry, lcname, name_len + 1, (void **)&module) == FAILURE) {
- free_alloca(lcname, use_heap);
- return;
- }
- free_alloca(lcname, use_heap);
- reflection_instantiate(reflection_extension_ptr, object TSRMLS_CC);
- intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC);
- MAKE_STD_ZVAL(name);
- ZVAL_STRINGL(name, module->name, name_len, 1);
- intern->ptr = module;
- intern->ref_type = REF_TYPE_OTHER;
- intern->ce = NULL;
- reflection_update_property(object, "name", name);
- }
- /* }}} */
- /* {{{ reflection_parameter_factory */
- static void reflection_parameter_factory(zend_function *fptr, zval *closure_object, struct _zend_arg_info *arg_info, zend_uint offset, zend_uint required, zval *object TSRMLS_DC)
- {
- reflection_object *intern;
- parameter_reference *reference;
- zval *name;
- if (closure_object) {
- Z_ADDREF_P(closure_object);
- }
- MAKE_STD_ZVAL(name);
- if (arg_info->name) {
- ZVAL_STRINGL(name, arg_info->name, arg_info->name_len, 1);
- } else {
- ZVAL_NULL(name);
- }
- reflection_instantiate(reflection_parameter_ptr, object TSRMLS_CC);
- intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC);
- reference = (parameter_reference*) emalloc(sizeof(parameter_reference));
- reference->arg_info = arg_info;
- reference->offset = offset;
- reference->required = required;
- reference->fptr = fptr;
- intern->ptr = reference;
- intern->ref_type = REF_TYPE_PARAMETER;
- intern->ce = fptr->common.scope;
- intern->obj = closure_object;
- reflection_update_property(object, "name", name);
- }
- /* }}} */
- /* {{{ reflection_function_factory */
- static void reflection_function_factory(zend_function *function, zval *closure_object, zval *object TSRMLS_DC)
- {
- reflection_object *intern;
- zval *name;
- if (closure_object) {
- Z_ADDREF_P(closure_object);
- }
- MAKE_STD_ZVAL(name);
- ZVAL_STRING(name, function->common.function_name, 1);
- reflection_instantiate(reflection_function_ptr, object TSRMLS_CC);
- intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC);
- intern->ptr = function;
- intern->ref_type = REF_TYPE_FUNCTION;
- intern->ce = NULL;
- intern->obj = closure_object;
- reflection_update_property(object, "name", name);
- }
- /* }}} */
- /* {{{ reflection_method_factory */
- static void reflection_method_factory(zend_class_entry *ce, zend_function *method, zval *closure_object, zval *object TSRMLS_DC)
- {
- reflection_object *intern;
- zval *name;
- zval *classname;
- if (closure_object) {
- Z_ADDREF_P(closure_object);
- }
- MAKE_STD_ZVAL(name);
- MAKE_STD_ZVAL(classname);
- ZVAL_STRING(name, (method->common.scope && method->common.scope->trait_aliases)?
- zend_resolve_method_name(ce, method) : method->common.function_name, 1);
- ZVAL_STRINGL(classname, method->common.scope->name, method->common.scope->name_length, 1);
- reflection_instantiate(reflection_method_ptr, object TSRMLS_CC);
- intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC);
- intern->ptr = method;
- intern->ref_type = REF_TYPE_FUNCTION;
- intern->ce = ce;
- intern->obj = closure_object;
- reflection_update_property(object, "name", name);
- reflection_update_property(object, "class", classname);
- }
- /* }}} */
- /* {{{ reflection_property_factory */
- static void reflection_property_factory(zend_class_entry *ce, zend_property_info *prop, zval *object TSRMLS_DC)
- {
- reflection_object *intern;
- zval *name;
- zval *classname;
- property_reference *reference;
- const char *class_name, *prop_name;
- zend_unmangle_property_name(prop->name, prop->name_length, &class_name, &prop_name);
- if (!(prop->flags & ZEND_ACC_PRIVATE)) {
- /* we have to search the class hierarchy for this (implicit) public or protected property */
- zend_class_entry *tmp_ce = ce, *store_ce = ce;
- zend_property_info *tmp_info = NULL;
- while (tmp_ce && zend_hash_find(&tmp_ce->properties_info, prop_name, strlen(prop_name) + 1, (void **) &tmp_info) != SUCCESS) {
- ce = tmp_ce;
- tmp_ce = tmp_ce->parent;
- }
- if (tmp_info && !(tmp_info->flags & ZEND_ACC_SHADOW)) { /* found something and it's not a parent's private */
- prop = tmp_info;
- } else { /* not found, use initial value */
- ce = store_ce;
- }
- }
- MAKE_STD_ZVAL(name);
- MAKE_STD_ZVAL(classname);
- ZVAL_STRING(name, prop_name, 1);
- ZVAL_STRINGL(classname, prop->ce->name, prop->ce->name_length, 1);
- reflection_instantiate(reflection_property_ptr, object TSRMLS_CC);
- intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC);
- reference = (property_reference*) emalloc(sizeof(property_reference));
- reference->ce = ce;
- reference->prop = *prop;
- intern->ptr = reference;
- intern->ref_type = REF_TYPE_PROPERTY;
- intern->ce = ce;
- intern->ignore_visibility = 0;
- reflection_update_property(object, "name", name);
- reflection_update_property(object, "class", classname);
- }
- /* }}} */
- /* {{{ _reflection_export */
- static void _reflection_export(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *ce_ptr, int ctor_argc)
- {
- zval *reflector_ptr;
- zval output, *output_ptr = &output;
- zval *argument_ptr, *argument2_ptr;
- zval *retval_ptr, **params[2];
- int result;
- int return_output = 0;
- zend_fcall_info fci;
- zend_fcall_info_cache fcc;
- zval fname;
- if (ctor_argc == 1) {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &argument_ptr, &return_output) == FAILURE) {
- return;
- }
- } else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|b", &argument_ptr, &argument2_ptr, &return_output) == FAILURE) {
- return;
- }
- }
- INIT_PZVAL(&output);
- /* Create object */
- MAKE_STD_ZVAL(reflector_ptr);
- if (object_and_properties_init(reflector_ptr, ce_ptr, NULL) == FAILURE) {
- _DO_THROW("Could not create reflector");
- }
- /* Call __construct() */
- params[0] = &argument_ptr;
- params[1] = &argument2_ptr;
- fci.size = sizeof(fci);
- fci.function_table = NULL;
- fci.function_name = NULL;
- fci.symbol_table = NULL;
- fci.object_ptr = reflector_ptr;
- fci.retval_ptr_ptr = &retval_ptr;
- fci.param_count = ctor_argc;
- fci.params = params;
- fci.no_separation = 1;
- fcc.initialized = 1;
- fcc.function_handler = ce_ptr->constructor;
- fcc.calling_scope = ce_ptr;
- fcc.called_scope = Z_OBJCE_P(reflector_ptr);
- fcc.object_ptr = reflector_ptr;
- result = zend_call_function(&fci, &fcc TSRMLS_CC);
- if (retval_ptr) {
- zval_ptr_dtor(&retval_ptr);
- }
- if (EG(exception)) {
- zval_ptr_dtor(&reflector_ptr);
- return;
- }
- if (result == FAILURE) {
- zval_ptr_dtor(&reflector_ptr);
- _DO_THROW("Could not create reflector");
- }
- /* Call static reflection::export */
- ZVAL_BOOL(&output, return_output);
- params[0] = &reflector_ptr;
- params[1] = &output_ptr;
- ZVAL_STRINGL(&fname, "reflection::export", sizeof("reflection::export") - 1, 0);
- fci.function_table = &reflection_ptr->function_table;
- fci.function_name = &fname;
- fci.object_ptr = NULL;
- fci.retval_ptr_ptr = &retval_ptr;
- fci.param_count = 2;
- fci.params = params;
- fci.no_separation = 1;
- result = zend_call_function(&fci, NULL TSRMLS_CC);
- if (result == FAILURE && EG(exception) == NULL) {
- zval_ptr_dtor(&reflector_ptr);
- zval_ptr_dtor(&retval_ptr);
- _DO_THROW("Could not execute reflection::export()");
- }
- if (return_output) {
- COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr);
- } else {
- zval_ptr_dtor(&retval_ptr);
- }
- /* Destruct reflector which is no longer needed */
- zval_ptr_dtor(&reflector_ptr);
- }
- /* }}} */
- /* {{{ _reflection_param_get_default_param */
- static parameter_reference *_reflection_param_get_default_param(INTERNAL_FUNCTION_PARAMETERS)
- {
- reflection_object *intern;
- parameter_reference *param;
- intern = (reflection_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
- if (intern == NULL || intern->ptr == NULL) {
- if (EG(exception) && Z_OBJCE_P(EG(exception)) == reflection_exception_ptr) {
- return NULL;
- }
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Failed to retrieve the reflection object");
- }
- param = intern->ptr;
- if (param->fptr->type != ZEND_USER_FUNCTION) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Cannot determine default value for internal functions");
- return NULL;
- }
- return param;
- }
- /* }}} */
- /* {{{ _reflection_param_get_default_precv */
- static zend_op *_reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAMETERS, parameter_reference *param)
- {
- zend_op *precv;
- if (param == NULL) {
- return NULL;
- }
- precv = _get_recv_op((zend_op_array*)param->fptr, param->offset);
- if (!precv || precv->opcode != ZEND_RECV_INIT || precv->op2_type == IS_UNUSED) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Internal error: Failed to retrieve the default value");
- return NULL;
- }
- return precv;
- }
- /* }}} */
- /* {{{ Preventing __clone from being called */
- ZEND_METHOD(reflection, __clone)
- {
- /* Should never be executable */
- _DO_THROW("Cannot clone object using __clone()");
- }
- /* }}} */
- /* {{{ proto public static mixed Reflection::export(Reflector r [, bool return])
- Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */
- ZEND_METHOD(reflection, export)
- {
- zval *object, fname, *retval_ptr;
- int result;
- zend_bool return_output = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|b", &object, reflector_ptr, &return_output) == FAILURE) {
- return;
- }
- /* Invoke the __toString() method */
- ZVAL_STRINGL(&fname, "__tostring", sizeof("__tostring") - 1, 1);
- result= call_user_function_ex(NULL, &object, &fname, &retval_ptr, 0, NULL, 0, NULL TSRMLS_CC);
- zval_dtor(&fname);
- if (result == FAILURE) {
- _DO_THROW("Invocation of method __toString() failed");
- /* Returns from this function */
- }
- if (!retval_ptr) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::__toString() did not return anything", Z_OBJCE_P(object)->name);
- RETURN_FALSE;
- }
- if (return_output) {
- COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr);
- } else {
- /* No need for _r variant, return of __toString should always be a string */
- zend_print_zval(retval_ptr, 0);
- zend_printf("\n");
- zval_ptr_dtor(&retval_ptr);
- }
- }
- /* }}} */
- /* {{{ proto public static array Reflection::getModifierNames(int modifiers)
- Returns an array of modifier names */
- ZEND_METHOD(reflection, getModifierNames)
- {
- long modifiers;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &modifiers) == FAILURE) {
- return;
- }
- array_init(return_value);
- if (modifiers & (ZEND_ACC_ABSTRACT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) {
- add_next_index_stringl(return_value, "abstract", sizeof("abstract")-1, 1);
- }
- if (modifiers & (ZEND_ACC_FINAL | ZEND_ACC_FINAL_CLASS)) {
- add_next_index_stringl(return_value, "final", sizeof("final")-1, 1);
- }
- if (modifiers & ZEND_ACC_IMPLICIT_PUBLIC) {
- add_next_index_stringl(return_value, "public", sizeof("public")-1, 1);
- }
- /* These are mutually exclusive */
- switch (modifiers & ZEND_ACC_PPP_MASK) {
- case ZEND_ACC_PUBLIC:
- add_next_index_stringl(return_value, "public", sizeof("public")-1, 1);
- break;
- case ZEND_ACC_PRIVATE:
- add_next_index_stringl(return_value, "private", sizeof("private")-1, 1);
- break;
- case ZEND_ACC_PROTECTED:
- add_next_index_stringl(return_value, "protected", sizeof("protected")-1, 1);
- break;
- }
- if (modifiers & ZEND_ACC_STATIC) {
- add_next_index_stringl(return_value, "static", sizeof("static")-1, 1);
- }
- }
- /* }}} */
- /* {{{ proto public static mixed ReflectionFunction::export(string name [, bool return])
- Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */
- ZEND_METHOD(reflection_function, export)
- {
- _reflection_export(INTERNAL_FUNCTION_PARAM_PASSTHRU, reflection_function_ptr, 1);
- }
- /* }}} */
- /* {{{ proto public void ReflectionFunction::__construct(string name)
- Constructor. Throws an Exception in case the given function does not exist */
- ZEND_METHOD(reflection_function, __construct)
- {
- zval *name;
- zval *object;
- zval *closure = NULL;
- char *lcname;
- reflection_object *intern;
- zend_function *fptr;
- char *name_str;
- int name_len;
- object = getThis();
- intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC);
- if (intern == NULL) {
- return;
- }
- if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "O", &closure, zend_ce_closure) == SUCCESS) {
- fptr = (zend_function*)zend_get_closure_method_def(closure TSRMLS_CC);
- Z_ADDREF_P(closure);
- } else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len) == SUCCESS) {
- char *nsname;
- lcname = zend_str_tolower_dup(name_str, name_len);
- /* Ignore leading "\" */
- nsname = lcname;
- if (lcname[0] == '\\') {
- nsname = &lcname[1];
- name_len--;
- }
- if (zend_hash_find(EG(function_table), nsname, name_len + 1, (void **)&fptr) == FAILURE) {
- efree(lcname);
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Function %s() does not exist", name_str);
- return;
- }
- efree(lcname);
- } else {
- return;
- }
- MAKE_STD_ZVAL(name);
- ZVAL_STRING(name, fptr->common.function_name, 1);
- reflection_update_property(object, "name", name);
- intern->ptr = fptr;
- intern->ref_type = REF_TYPE_FUNCTION;
- intern->obj = closure;
- intern->ce = NULL;
- }
- /* }}} */
- /* {{{ proto public string ReflectionFunction::__toString()
- Returns a string representation */
- ZEND_METHOD(reflection_function, __toString)
- {
- reflection_object *intern;
- zend_function *fptr;
- string str;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(fptr);
- string_init(&str);
- _function_string(&str, fptr, intern->ce, "" TSRMLS_CC);
- RETURN_STRINGL(str.string, str.len - 1, 0);
- }
- /* }}} */
- /* {{{ proto public string ReflectionFunction::getName()
- Returns this function's name */
- ZEND_METHOD(reflection_function, getName)
- {
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- _default_get_entry(getThis(), "name", sizeof("name"), return_value TSRMLS_CC);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionFunction::isClosure()
- Returns whether this is a closure */
- ZEND_METHOD(reflection_function, isClosure)
- {
- reflection_object *intern;
- zend_function *fptr;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(fptr);
- RETURN_BOOL(fptr->common.fn_flags & ZEND_ACC_CLOSURE);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionFunction::getClosureThis()
- Returns this pointer bound to closure */
- ZEND_METHOD(reflection_function, getClosureThis)
- {
- reflection_object *intern;
- zend_function *fptr;
- zval* closure_this;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(fptr);
- if (intern->obj) {
- closure_this = zend_get_closure_this_ptr(intern->obj TSRMLS_CC);
- if (closure_this) {
- RETURN_ZVAL(closure_this, 1, 0);
- }
- }
- }
- /* }}} */
- /* {{{ proto public ReflectionClass ReflectionFunction::getClosureScopeClass()
- Returns the scope associated to the closure */
- ZEND_METHOD(reflection_function, getClosureScopeClass)
- {
- reflection_object *intern;
- zend_function *fptr;
- const zend_function *closure_func;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(fptr);
- if (intern->obj) {
- closure_func = zend_get_closure_method_def(intern->obj TSRMLS_CC);
- if (closure_func && closure_func->common.scope) {
- zend_reflection_class_factory(closure_func->common.scope, return_value TSRMLS_CC);
- }
- }
- }
- /* }}} */
- /* {{{ proto public mixed ReflectionFunction::getClosure()
- Returns a dynamically created closure for the function */
- ZEND_METHOD(reflection_function, getClosure)
- {
- reflection_object *intern;
- zend_function *fptr;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(fptr);
- zend_create_closure(return_value, fptr, NULL, NULL TSRMLS_CC);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionFunction::isInternal()
- Returns whether this is an internal function */
- ZEND_METHOD(reflection_function, isInternal)
- {
- reflection_object *intern;
- zend_function *fptr;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(fptr);
- RETURN_BOOL(fptr->type == ZEND_INTERNAL_FUNCTION);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionFunction::isUserDefined()
- Returns whether this is an user-defined function */
- ZEND_METHOD(reflection_function, isUserDefined)
- {
- reflection_object *intern;
- zend_function *fptr;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(fptr);
- RETURN_BOOL(fptr->type == ZEND_USER_FUNCTION);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionFunction::isDisabled()
- Returns whether this function has been disabled or not */
- ZEND_METHOD(reflection_function, isDisabled)
- {
- reflection_object *intern;
- zend_function *fptr;
- METHOD_NOTSTATIC(reflection_function_ptr);
- GET_REFLECTION_OBJECT_PTR(fptr);
- RETURN_BOOL(fptr->type == ZEND_INTERNAL_FUNCTION && fptr->internal_function.handler == zif_display_disabled_function);
- }
- /* }}} */
- /* {{{ proto public string ReflectionFunction::getFileName()
- Returns the filename of the file this function was declared in */
- ZEND_METHOD(reflection_function, getFileName)
- {
- reflection_object *intern;
- zend_function *fptr;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(fptr);
- if (fptr->type == ZEND_USER_FUNCTION) {
- RETURN_STRING(fptr->op_array.filename, 1);
- }
- RETURN_FALSE;
- }
- /* }}} */
- /* {{{ proto public int ReflectionFunction::getStartLine()
- Returns the line this function's declaration starts at */
- ZEND_METHOD(reflection_function, getStartLine)
- {
- reflection_object *intern;
- zend_function *fptr;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(fptr);
- if (fptr->type == ZEND_USER_FUNCTION) {
- RETURN_LONG(fptr->op_array.line_start);
- }
- RETURN_FALSE;
- }
- /* }}} */
- /* {{{ proto public int ReflectionFunction::getEndLine()
- Returns the line this function's declaration ends at */
- ZEND_METHOD(reflection_function, getEndLine)
- {
- reflection_object *intern;
- zend_function *fptr;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(fptr);
- if (fptr->type == ZEND_USER_FUNCTION) {
- RETURN_LONG(fptr->op_array.line_end);
- }
- RETURN_FALSE;
- }
- /* }}} */
- /* {{{ proto public string ReflectionFunction::getDocComment()
- Returns the doc comment for this function */
- ZEND_METHOD(reflection_function, getDocComment)
- {
- reflection_object *intern;
- zend_function *fptr;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(fptr);
- if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.doc_comment) {
- RETURN_STRINGL(fptr->op_array.doc_comment, fptr->op_array.doc_comment_len, 1);
- }
- RETURN_FALSE;
- }
- /* }}} */
- /* {{{ proto public array ReflectionFunction::getStaticVariables()
- Returns an associative array containing this function's static variables and their values */
- ZEND_METHOD(reflection_function, getStaticVariables)
- {
- zval *tmp_copy;
- reflection_object *intern;
- zend_function *fptr;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(fptr);
- /* Return an empty array in case no static variables exist */
- array_init(return_value);
- if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.static_variables != NULL) {
- zend_hash_apply_with_argument(fptr->op_array.static_variables, (apply_func_arg_t) zval_update_constant_inline_change, fptr->common.scope TSRMLS_CC);
- zend_hash_copy(Z_ARRVAL_P(return_value), fptr->op_array.static_variables, (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(zval *));
- }
- }
- /* }}} */
- /* {{{ proto public mixed ReflectionFunction::invoke([mixed* args])
- Invokes the function */
- ZEND_METHOD(reflection_function, invoke)
- {
- zval *retval_ptr;
- zval ***params = NULL;
- int result, num_args = 0;
- zend_fcall_info fci;
- zend_fcall_info_cache fcc;
- reflection_object *intern;
- zend_function *fptr;
- METHOD_NOTSTATIC(reflection_function_ptr);
- GET_REFLECTION_OBJECT_PTR(fptr);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "*", ¶ms, &num_args) == FAILURE) {
- return;
- }
- fci.size = sizeof(fci);
- fci.function_table = NULL;
- fci.function_name = NULL;
- fci.symbol_table = NULL;
- fci.object_ptr = NULL;
- fci.retval_ptr_ptr = &retval_ptr;
- fci.param_count = num_args;
- fci.params = params;
- fci.no_separation = 1;
- fcc.initialized = 1;
- fcc.function_handler = fptr;
- fcc.calling_scope = EG(scope);
- fcc.called_scope = NULL;
- fcc.object_ptr = NULL;
- result = zend_call_function(&fci, &fcc TSRMLS_CC);
- if (num_args) {
- efree(params);
- }
- if (result == FAILURE) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Invocation of function %s() failed", fptr->common.function_name);
- return;
- }
- if (retval_ptr) {
- COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr);
- }
- }
- /* }}} */
- static int _zval_array_to_c_array(zval **arg, zval ****params TSRMLS_DC) /* {{{ */
- {
- *(*params)++ = arg;
- return ZEND_HASH_APPLY_KEEP;
- } /* }}} */
- /* {{{ proto public mixed ReflectionFunction::invokeArgs(array args)
- Invokes the function and pass its arguments as array. */
- ZEND_METHOD(reflection_function, invokeArgs)
- {
- zval *retval_ptr;
- zval ***params;
- int result;
- int argc;
- zend_fcall_info fci;
- zend_fcall_info_cache fcc;
- reflection_object *intern;
- zend_function *fptr;
- zval *param_array;
- METHOD_NOTSTATIC(reflection_function_ptr);
- GET_REFLECTION_OBJECT_PTR(fptr);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", ¶m_array) == FAILURE) {
- return;
- }
- argc = zend_hash_num_elements(Z_ARRVAL_P(param_array));
- params = safe_emalloc(sizeof(zval **), argc, 0);
- zend_hash_apply_with_argument(Z_ARRVAL_P(param_array), (apply_func_arg_t)_zval_array_to_c_array, ¶ms TSRMLS_CC);
- params -= argc;
- fci.size = sizeof(fci);
- fci.function_table = NULL;
- fci.function_name = NULL;
- fci.symbol_table = NULL;
- fci.object_ptr = NULL;
- fci.retval_ptr_ptr = &retval_ptr;
- fci.param_count = argc;
- fci.params = params;
- fci.no_separation = 1;
- fcc.initialized = 1;
- fcc.function_handler = fptr;
- fcc.calling_scope = EG(scope);
- fcc.called_scope = NULL;
- fcc.object_ptr = NULL;
- result = zend_call_function(&fci, &fcc TSRMLS_CC);
- efree(params);
- if (result == FAILURE) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Invocation of function %s() failed", fptr->common.function_name);
- return;
- }
- if (retval_ptr) {
- COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr);
- }
- }
- /* }}} */
- /* {{{ proto public bool ReflectionFunction::returnsReference()
- Gets whether this function returns a reference */
- ZEND_METHOD(reflection_function, returnsReference)
- {
- reflection_object *intern;
- zend_function *fptr;
- METHOD_NOTSTATIC(reflection_function_abstract_ptr);
- GET_REFLECTION_OBJECT_PTR(fptr);
- RETURN_BOOL((fptr->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionFunction::getNumberOfParameters()
- Gets the number of required parameters */
- ZEND_METHOD(reflection_function, getNumberOfParameters)
- {
- reflection_object *intern;
- zend_function *fptr;
- METHOD_NOTSTATIC(reflection_function_abstract_ptr);
- GET_REFLECTION_OBJECT_PTR(fptr);
- RETURN_LONG(fptr->common.num_args);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionFunction::getNumberOfRequiredParameters()
- Gets the number of required parameters */
- ZEND_METHOD(reflection_function, getNumberOfRequiredParameters)
- {
- reflection_object *intern;
- zend_function *fptr;
- METHOD_NOTSTATIC(reflection_function_abstract_ptr);
- GET_REFLECTION_OBJECT_PTR(fptr);
- RETURN_LONG(fptr->common.required_num_args);
- }
- /* }}} */
- /* {{{ proto public ReflectionParameter[] ReflectionFunction::getParameters()
- Returns an array of parameter objects for this function */
- ZEND_METHOD(reflection_function, getParameters)
- {
- reflection_object *intern;
- zend_function *fptr;
- zend_uint i;
- struct _zend_arg_info *arg_info;
- METHOD_NOTSTATIC(reflection_function_abstract_ptr);
- GET_REFLECTION_OBJECT_PTR(fptr);
- arg_info= fptr->common.arg_info;
- array_init(return_value);
- for (i = 0; i < fptr->common.num_args; i++) {
- zval *parameter;
- ALLOC_ZVAL(parameter);
- reflection_parameter_factory(_copy_function(fptr TSRMLS_CC), intern->obj, arg_info, i, fptr->common.required_num_args, parameter TSRMLS_CC);
- add_next_index_zval(return_value, parameter);
- arg_info++;
- }
- }
- /* }}} */
- /* {{{ proto public ReflectionExtension|NULL ReflectionFunction::getExtension()
- Returns NULL or the extension the function belongs to */
- ZEND_METHOD(reflection_function, getExtension)
- {
- reflection_object *intern;
- zend_function *fptr;
- zend_internal_function *internal;
- METHOD_NOTSTATIC(reflection_function_abstract_ptr);
- GET_REFLECTION_OBJECT_PTR(fptr);
- if (fptr->type != ZEND_INTERNAL_FUNCTION) {
- RETURN_NULL();
- }
- internal = (zend_internal_function *)fptr;
- if (internal->module) {
- reflection_extension_factory(return_value, internal->module->name TSRMLS_CC);
- } else {
- RETURN_NULL();
- }
- }
- /* }}} */
- /* {{{ proto public string|false ReflectionFunction::getExtensionName()
- Returns false or the name of the extension the function belongs to */
- ZEND_METHOD(reflection_function, getExtensionName)
- {
- reflection_object *intern;
- zend_function *fptr;
- zend_internal_function *internal;
- METHOD_NOTSTATIC(reflection_function_abstract_ptr);
- GET_REFLECTION_OBJECT_PTR(fptr);
- if (fptr->type != ZEND_INTERNAL_FUNCTION) {
- RETURN_FALSE;
- }
- internal = (zend_internal_function *)fptr;
- if (internal->module) {
- RETURN_STRING(internal->module->name, 1);
- } else {
- RETURN_FALSE;
- }
- }
- /* }}} */
- /* {{{ proto public static mixed ReflectionParameter::export(mixed function, mixed parameter [, bool return]) throws ReflectionException
- Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */
- ZEND_METHOD(reflection_parameter, export)
- {
- _reflection_export(INTERNAL_FUNCTION_PARAM_PASSTHRU, reflection_parameter_ptr, 2);
- }
- /* }}} */
- /* {{{ proto public void ReflectionParameter::__construct(mixed function, mixed parameter)
- Constructor. Throws an Exception in case the given method does not exist */
- ZEND_METHOD(reflection_parameter, __construct)
- {
- parameter_reference *ref;
- zval *reference, **parameter;
- zval *object;
- zval *name;
- reflection_object *intern;
- zend_function *fptr;
- struct _zend_arg_info *arg_info;
- int position;
- zend_class_entry *ce = NULL;
- zend_bool is_closure = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zZ", &reference, ¶meter) == FAILURE) {
- return;
- }
- object = getThis();
- intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC);
- if (intern == NULL) {
- return;
- }
- /* First, find the function */
- switch (Z_TYPE_P(reference)) {
- case IS_STRING: {
- unsigned int lcname_len;
- char *lcname;
- lcname_len = Z_STRLEN_P(reference);
- lcname = zend_str_tolower_dup(Z_STRVAL_P(reference), lcname_len);
- if (zend_hash_find(EG(function_table), lcname, lcname_len + 1, (void**) &fptr) == FAILURE) {
- efree(lcname);
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Function %s() does not exist", Z_STRVAL_P(reference));
- return;
- }
- efree(lcname);
- }
- ce = fptr->common.scope;
- break;
- case IS_ARRAY: {
- zval **classref;
- zval **method;
- zend_class_entry **pce;
- unsigned int lcname_len;
- char *lcname;
- if ((zend_hash_index_find(Z_ARRVAL_P(reference), 0, (void **) &classref) == FAILURE)
- || (zend_hash_index_find(Z_ARRVAL_P(reference), 1, (void **) &method) == FAILURE))
- {
- _DO_THROW("Expected array($object, $method) or array($classname, $method)");
- /* returns out of this function */
- }
- if (Z_TYPE_PP(classref) == IS_OBJECT) {
- ce = Z_OBJCE_PP(classref);
- } else {
- convert_to_string_ex(classref);
- if (zend_lookup_class(Z_STRVAL_PP(classref), Z_STRLEN_PP(classref), &pce TSRMLS_CC) == FAILURE) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Class %s does not exist", Z_STRVAL_PP(classref));
- return;
- }
- ce = *pce;
- }
- convert_to_string_ex(method);
- lcname_len = Z_STRLEN_PP(method);
- lcname = zend_str_tolower_dup(Z_STRVAL_PP(method), lcname_len);
- if (ce == zend_ce_closure && Z_TYPE_PP(classref) == IS_OBJECT
- && (lcname_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1)
- && memcmp(lcname, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0
- && (fptr = zend_get_closure_invoke_method(*classref TSRMLS_CC)) != NULL)
- {
- /* nothing to do. don't set is_closure since is the invoke handler,
- - not the closure itself */
- } else if (zend_hash_find(&ce->function_table, lcname, lcname_len + 1, (void **) &fptr) == FAILURE) {
- efree(lcname);
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Method %s::%s() does not exist", ce->name, Z_STRVAL_PP(method));
- return;
- }
- efree(lcname);
- }
- break;
- case IS_OBJECT: {
- ce = Z_OBJCE_P(reference);
- if (instanceof_function(ce, zend_ce_closure TSRMLS_CC)) {
- fptr = (zend_function *)zend_get_closure_method_def(reference TSRMLS_CC);
- Z_ADDREF_P(reference);
- is_closure = 1;
- } else if (zend_hash_find(&ce->function_table, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME), (void **)&fptr) == FAILURE) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Method %s::%s() does not exist", ce->name, ZEND_INVOKE_FUNC_NAME);
- return;
- }
- }
- break;
- default:
- _DO_THROW("The parameter class is expected to be either a string, an array(class, method) or a callable object");
- /* returns out of this function */
- }
- /* Now, search for the parameter */
- arg_info = fptr->common.arg_info;
- if (Z_TYPE_PP(parameter) == IS_LONG) {
- position= Z_LVAL_PP(parameter);
- if (position < 0 || (zend_uint)position >= fptr->common.num_args) {
- if (fptr->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) {
- if (fptr->type != ZEND_OVERLOADED_FUNCTION) {
- efree((char*)fptr->common.function_name);
- }
- efree(fptr);
- }
- if (is_closure) {
- zval_ptr_dtor(&reference);
- }
- _DO_THROW("The parameter specified by its offset could not be found");
- /* returns out of this function */
- }
- } else {
- zend_uint i;
- position= -1;
- convert_to_string_ex(parameter);
- for (i = 0; i < fptr->common.num_args; i++) {
- if (arg_info[i].name && strcmp(arg_info[i].name, Z_STRVAL_PP(parameter)) == 0) {
- position= i;
- break;
- }
- }
- if (position == -1) {
- if (fptr->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) {
- if (fptr->type != ZEND_OVERLOADED_FUNCTION) {
- efree((char*)fptr->common.function_name);
- }
- efree(fptr);
- }
- if (is_closure) {
- zval_ptr_dtor(&reference);
- }
- _DO_THROW("The parameter specified by its name could not be found");
- /* returns out of this function */
- }
- }
- MAKE_STD_ZVAL(name);
- if (arg_info[position].name) {
- ZVAL_STRINGL(name, arg_info[position].name, arg_info[position].name_len, 1);
- } else {
- ZVAL_NULL(name);
- }
- reflection_update_property(object, "name", name);
- ref = (parameter_reference*) emalloc(sizeof(parameter_reference));
- ref->arg_info = &arg_info[position];
- ref->offset = (zend_uint)position;
- ref->required = fptr->common.required_num_args;
- ref->fptr = fptr;
- /* TODO: copy fptr */
- intern->ptr = ref;
- intern->ref_type = REF_TYPE_PARAMETER;
- intern->ce = ce;
- if (reference && is_closure) {
- intern->obj = reference;
- }
- }
- /* }}} */
- /* {{{ proto public string ReflectionParameter::__toString()
- Returns a string representation */
- ZEND_METHOD(reflection_parameter, __toString)
- {
- reflection_object *intern;
- parameter_reference *param;
- string str;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(param);
- string_init(&str);
- _parameter_string(&str, param->fptr, param->arg_info, param->offset, param->required, "" TSRMLS_CC);
- RETURN_STRINGL(str.string, str.len - 1, 0);
- }
- /* }}} */
- /* {{{ proto public string ReflectionParameter::getName()
- Returns this parameters's name */
- ZEND_METHOD(reflection_parameter, getName)
- {
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- _default_get_entry(getThis(), "name", sizeof("name"), return_value TSRMLS_CC);
- }
- /* }}} */
- /* {{{ proto public ReflectionFunction ReflectionParameter::getDeclaringFunction()
- Returns the ReflectionFunction for the function of this parameter */
- ZEND_METHOD(reflection_parameter, getDeclaringFunction)
- {
- reflection_object *intern;
- parameter_reference *param;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(param);
- if (!param->fptr->common.scope) {
- reflection_function_factory(_copy_function(param->fptr TSRMLS_CC), intern->obj, return_value TSRMLS_CC);
- } else {
- reflection_method_factory(param->fptr->common.scope, _copy_function(param->fptr TSRMLS_CC), intern->obj, return_value TSRMLS_CC);
- }
- }
- /* }}} */
- /* {{{ proto public ReflectionClass|NULL ReflectionParameter::getDeclaringClass()
- Returns in which class this parameter is defined (not the typehint of the parameter) */
- ZEND_METHOD(reflection_parameter, getDeclaringClass)
- {
- reflection_object *intern;
- parameter_reference *param;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(param);
- if (param->fptr->common.scope) {
- zend_reflection_class_factory(param->fptr->common.scope, return_value TSRMLS_CC);
- }
- }
- /* }}} */
- /* {{{ proto public ReflectionClass|NULL ReflectionParameter::getClass()
- Returns this parameters's class hint or NULL if there is none */
- ZEND_METHOD(reflection_parameter, getClass)
- {
- reflection_object *intern;
- parameter_reference *param;
- zend_class_entry **pce, *ce;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(param);
- if (param->arg_info->class_name) {
- /* Class name is stored as a string, we might also get "self" or "parent"
- * - For "self", simply use the function scope. If scope is NULL then
- * the function is global and thus self does not make any sense
- *
- * - For "parent", use the function scope's parent. If scope is NULL then
- * the function is global and thus parent does not make any sense.
- * If the parent is NULL then the class does not extend anything and
- * thus parent does not make any sense, either.
- *
- * TODO: Think about moving these checks to the compiler or some sort of
- * lint-mode.
- */
- if (0 == zend_binary_strcasecmp(param->arg_info->class_name, param->arg_info->class_name_len, "self", sizeof("self")- 1)) {
- ce = param->fptr->common.scope;
- if (!ce) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Parameter uses 'self' as type hint but function is not a class member!");
- return;
- }
- pce= &ce;
- } else if (0 == zend_binary_strcasecmp(param->arg_info->class_name, param->arg_info->class_name_len, "parent", sizeof("parent")- 1)) {
- ce = param->fptr->common.scope;
- if (!ce) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Parameter uses 'parent' as type hint but function is not a class member!");
- return;
- }
- if (!ce->parent) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Parameter uses 'parent' as type hint although class does not have a parent!");
- return;
- }
- pce= &ce->parent;
- } else if (zend_lookup_class(param->arg_info->class_name, param->arg_info->class_name_len, &pce TSRMLS_CC) == FAILURE) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Class %s does not exist", param->arg_info->class_name);
- return;
- }
- zend_reflection_class_factory(*pce, return_value TSRMLS_CC);
- }
- }
- /* }}} */
- /* {{{ proto public bool ReflectionParameter::isArray()
- Returns whether parameter MUST be an array */
- ZEND_METHOD(reflection_parameter, isArray)
- {
- reflection_object *intern;
- parameter_reference *param;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(param);
- RETVAL_BOOL(param->arg_info->type_hint == IS_ARRAY);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionParameter::isCallable()
- Returns whether parameter MUST be callable */
- ZEND_METHOD(reflection_parameter, isCallable)
- {
- reflection_object *intern;
- parameter_reference *param;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(param);
- RETVAL_BOOL(param->arg_info->type_hint == IS_CALLABLE);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionParameter::allowsNull()
- Returns whether NULL is allowed as this parameters's value */
- ZEND_METHOD(reflection_parameter, allowsNull)
- {
- reflection_object *intern;
- parameter_reference *param;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(param);
- RETVAL_BOOL(param->arg_info->allow_null);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionParameter::isPassedByReference()
- Returns whether this parameters is passed to by reference */
- ZEND_METHOD(reflection_parameter, isPassedByReference)
- {
- reflection_object *intern;
- parameter_reference *param;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(param);
- RETVAL_BOOL(param->arg_info->pass_by_reference);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionParameter::canBePassedByValue()
- Returns whether this parameter can be passed by value */
- ZEND_METHOD(reflection_parameter, canBePassedByValue)
- {
- reflection_object *intern;
- parameter_reference *param;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(param);
- /* true if it's ZEND_SEND_BY_VAL or ZEND_SEND_PREFER_REF */
- RETVAL_BOOL(param->arg_info->pass_by_reference != ZEND_SEND_BY_REF);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionParameter::getPosition()
- Returns whether this parameter is an optional parameter */
- ZEND_METHOD(reflection_parameter, getPosition)
- {
- reflection_object *intern;
- parameter_reference *param;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(param);
- RETVAL_LONG(param->offset);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionParameter::isOptional()
- Returns whether this parameter is an optional parameter */
- ZEND_METHOD(reflection_parameter, isOptional)
- {
- reflection_object *intern;
- parameter_reference *param;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(param);
- RETVAL_BOOL(param->offset >= param->required);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionParameter::isDefaultValueAvailable()
- Returns whether the default value of this parameter is available */
- ZEND_METHOD(reflection_parameter, isDefaultValueAvailable)
- {
- reflection_object *intern;
- parameter_reference *param;
- zend_op *precv;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(param);
- if (param->fptr->type != ZEND_USER_FUNCTION)
- {
- RETURN_FALSE;
- }
- precv = _get_recv_op((zend_op_array*)param->fptr, param->offset);
- if (!precv || precv->opcode != ZEND_RECV_INIT || precv->op2_type == IS_UNUSED) {
- RETURN_FALSE;
- }
- RETURN_TRUE;
- }
- /* }}} */
- /* {{{ proto public bool ReflectionParameter::getDefaultValue()
- Returns the default value of this parameter or throws an exception */
- ZEND_METHOD(reflection_parameter, getDefaultValue)
- {
- parameter_reference *param;
- zend_op *precv;
- zend_class_entry *old_scope;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- param = _reflection_param_get_default_param(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- if (!param) {
- return;
- }
- precv = _reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAM_PASSTHRU, param);
- if (!precv) {
- return;
- }
- *return_value = *precv->op2.zv;
- INIT_PZVAL(return_value);
- if (!IS_CONSTANT_TYPE(Z_TYPE_P(return_value))) {
- if (Z_TYPE_P(return_value) != IS_ARRAY) {
- zval_copy_ctor(return_value);
- } else {
- HashTable *ht;
- ALLOC_HASHTABLE(ht);
- zend_hash_init(ht, zend_hash_num_elements(Z_ARRVAL_P(return_value)), NULL, ZVAL_PTR_DTOR, 0);
- zend_hash_copy(ht, Z_ARRVAL_P(return_value), (copy_ctor_func_t) reflection_zval_deep_copy, NULL, sizeof(zval *));
- Z_ARRVAL_P(return_value) = ht;
- }
- }
- old_scope = EG(scope);
- EG(scope) = param->fptr->common.scope;
- zval_update_constant_ex(&return_value, 0, NULL TSRMLS_CC);
- EG(scope) = old_scope;
- }
- /* }}} */
- /* {{{ proto public bool ReflectionParameter::isDefaultValueConstant()
- Returns whether the default value of this parameter is constant */
- ZEND_METHOD(reflection_parameter, isDefaultValueConstant)
- {
- zend_op *precv;
- parameter_reference *param;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- param = _reflection_param_get_default_param(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- if (!param) {
- RETURN_FALSE;
- }
- precv = _reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAM_PASSTHRU, param);
- if (precv && (Z_TYPE_P(precv->op2.zv) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) {
- RETURN_TRUE;
- }
- RETURN_FALSE;
- }
- /* }}} */
- /* {{{ proto public mixed ReflectionParameter::getDefaultValueConstantName()
- Returns the default value's constant name if default value is constant or null */
- ZEND_METHOD(reflection_parameter, getDefaultValueConstantName)
- {
- zend_op *precv;
- parameter_reference *param;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- param = _reflection_param_get_default_param(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- if (!param) {
- return;
- }
- precv = _reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAM_PASSTHRU, param);
- if (precv && (Z_TYPE_P(precv->op2.zv) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) {
- RETURN_STRINGL(Z_STRVAL_P(precv->op2.zv), Z_STRLEN_P(precv->op2.zv), 1);
- }
- }
- /* }}} */
- /* {{{ proto public bool ReflectionParameter::isVariadic()
- Returns whether this parameter is a variadic parameter */
- ZEND_METHOD(reflection_parameter, isVariadic)
- {
- reflection_object *intern;
- parameter_reference *param;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(param);
- RETVAL_BOOL(param->arg_info->is_variadic);
- }
- /* }}} */
- /* {{{ proto public static mixed ReflectionMethod::export(mixed class, string name [, bool return]) throws ReflectionException
- Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */
- ZEND_METHOD(reflection_method, export)
- {
- _reflection_export(INTERNAL_FUNCTION_PARAM_PASSTHRU, reflection_method_ptr, 2);
- }
- /* }}} */
- /* {{{ proto public void ReflectionMethod::__construct(mixed class_or_method [, string name])
- Constructor. Throws an Exception in case the given method does not exist */
- ZEND_METHOD(reflection_method, __construct)
- {
- zval *name, *classname;
- zval *object, *orig_obj;
- reflection_object *intern;
- char *lcname;
- zend_class_entry **pce;
- zend_class_entry *ce;
- zend_function *mptr;
- char *name_str, *tmp;
- int name_len, tmp_len;
- zval ztmp;
- if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "zs", &classname, &name_str, &name_len) == FAILURE) {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len) == FAILURE) {
- return;
- }
- if ((tmp = strstr(name_str, "::")) == NULL) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Invalid method name %s", name_str);
- return;
- }
- classname = &ztmp;
- tmp_len = tmp - name_str;
- ZVAL_STRINGL(classname, name_str, tmp_len, 1);
- name_len = name_len - (tmp_len + 2);
- name_str = tmp + 2;
- orig_obj = NULL;
- } else if (Z_TYPE_P(classname) == IS_OBJECT) {
- orig_obj = classname;
- } else {
- orig_obj = NULL;
- }
- object = getThis();
- intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC);
- if (intern == NULL) {
- return;
- }
- /* Find the class entry */
- switch (Z_TYPE_P(classname)) {
- case IS_STRING:
- if (zend_lookup_class(Z_STRVAL_P(classname), Z_STRLEN_P(classname), &pce TSRMLS_CC) == FAILURE) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Class %s does not exist", Z_STRVAL_P(classname));
- if (classname == &ztmp) {
- zval_dtor(&ztmp);
- }
- return;
- }
- ce = *pce;
- break;
- case IS_OBJECT:
- ce = Z_OBJCE_P(classname);
- break;
- default:
- if (classname == &ztmp) {
- zval_dtor(&ztmp);
- }
- _DO_THROW("The parameter class is expected to be either a string or an object");
- /* returns out of this function */
- }
- if (classname == &ztmp) {
- zval_dtor(&ztmp);
- }
- lcname = zend_str_tolower_dup(name_str, name_len);
- if (ce == zend_ce_closure && orig_obj && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1)
- && memcmp(lcname, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0
- && (mptr = zend_get_closure_invoke_method(orig_obj TSRMLS_CC)) != NULL)
- {
- /* do nothing, mptr already set */
- } else if (zend_hash_find(&ce->function_table, lcname, name_len + 1, (void **) &mptr) == FAILURE) {
- efree(lcname);
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Method %s::%s() does not exist", ce->name, name_str);
- return;
- }
- efree(lcname);
- MAKE_STD_ZVAL(classname);
- ZVAL_STRINGL(classname, mptr->common.scope->name, mptr->common.scope->name_length, 1);
- reflection_update_property(object, "class", classname);
- MAKE_STD_ZVAL(name);
- ZVAL_STRING(name, mptr->common.function_name, 1);
- reflection_update_property(object, "name", name);
- intern->ptr = mptr;
- intern->ref_type = REF_TYPE_FUNCTION;
- intern->ce = ce;
- }
- /* }}} */
- /* {{{ proto public string ReflectionMethod::__toString()
- Returns a string representation */
- ZEND_METHOD(reflection_method, __toString)
- {
- reflection_object *intern;
- zend_function *mptr;
- string str;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(mptr);
- string_init(&str);
- _function_string(&str, mptr, intern->ce, "" TSRMLS_CC);
- RETURN_STRINGL(str.string, str.len - 1, 0);
- }
- /* }}} */
- /* {{{ proto public mixed ReflectionMethod::getClosure([mixed object])
- Invokes the function */
- ZEND_METHOD(reflection_method, getClosure)
- {
- reflection_object *intern;
- zval *obj;
- zend_function *mptr;
- METHOD_NOTSTATIC(reflection_method_ptr);
- GET_REFLECTION_OBJECT_PTR(mptr);
- if (mptr->common.fn_flags & ZEND_ACC_STATIC) {
- zend_create_closure(return_value, mptr, mptr->common.scope, NULL TSRMLS_CC);
- } else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) {
- return;
- }
- if (!instanceof_function(Z_OBJCE_P(obj), mptr->common.scope TSRMLS_CC)) {
- _DO_THROW("Given object is not an instance of the class this method was declared in");
- /* Returns from this function */
- }
- /* This is an original closure object and __invoke is to be called. */
- if (Z_OBJCE_P(obj) == zend_ce_closure && mptr->type == ZEND_INTERNAL_FUNCTION &&
- (mptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0)
- {
- RETURN_ZVAL(obj, 1, 0);
- } else {
- zend_create_closure(return_value, mptr, mptr->common.scope, obj TSRMLS_CC);
- }
- }
- }
- /* }}} */
- /* {{{ proto public mixed ReflectionMethod::invoke(mixed object, mixed* args)
- Invokes the method. */
- ZEND_METHOD(reflection_method, invoke)
- {
- zval *retval_ptr;
- zval ***params = NULL;
- zval *object_ptr;
- reflection_object *intern;
- zend_function *mptr;
- int result, num_args = 0;
- zend_fcall_info fci;
- zend_fcall_info_cache fcc;
- zend_class_entry *obj_ce;
- METHOD_NOTSTATIC(reflection_method_ptr);
- GET_REFLECTION_OBJECT_PTR(mptr);
- if ((!(mptr->common.fn_flags & ZEND_ACC_PUBLIC)
- || (mptr->common.fn_flags & ZEND_ACC_ABSTRACT))
- && intern->ignore_visibility == 0)
- {
- if (mptr->common.fn_flags & ZEND_ACC_ABSTRACT) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Trying to invoke abstract method %s::%s()",
- mptr->common.scope->name, mptr->common.function_name);
- } else {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Trying to invoke %s method %s::%s() from scope %s",
- mptr->common.fn_flags & ZEND_ACC_PROTECTED ? "protected" : "private",
- mptr->common.scope->name, mptr->common.function_name,
- Z_OBJCE_P(getThis())->name);
- }
- return;
- }
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", ¶ms, &num_args) == FAILURE) {
- return;
- }
- /* In case this is a static method, we should'nt pass an object_ptr
- * (which is used as calling context aka $this). We can thus ignore the
- * first parameter.
- *
- * Else, we verify that the given object is an instance of the class.
- */
- if (mptr->common.fn_flags & ZEND_ACC_STATIC) {
- object_ptr = NULL;
- obj_ce = mptr->common.scope;
- } else {
- if (Z_TYPE_PP(params[0]) != IS_OBJECT) {
- efree(params);
- _DO_THROW("Non-object passed to Invoke()");
- /* Returns from this function */
- }
- obj_ce = Z_OBJCE_PP(params[0]);
- if (!instanceof_function(obj_ce, mptr->common.scope TSRMLS_CC)) {
- if (params) {
- efree(params);
- }
- _DO_THROW("Given object is not an instance of the class this method was declared in");
- /* Returns from this function */
- }
- object_ptr = *params[0];
- }
- fci.size = sizeof(fci);
- fci.function_table = NULL;
- fci.function_name = NULL;
- fci.symbol_table = NULL;
- fci.object_ptr = object_ptr;
- fci.retval_ptr_ptr = &retval_ptr;
- fci.param_count = num_args - 1;
- fci.params = params + 1;
- fci.no_separation = 1;
- fcc.initialized = 1;
- fcc.function_handler = mptr;
- fcc.calling_scope = obj_ce;
- fcc.called_scope = intern->ce;
- fcc.object_ptr = object_ptr;
- result = zend_call_function(&fci, &fcc TSRMLS_CC);
- if (params) {
- efree(params);
- }
- if (result == FAILURE) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Invocation of method %s::%s() failed", mptr->common.scope->name, mptr->common.function_name);
- return;
- }
- if (retval_ptr) {
- COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr);
- }
- }
- /* }}} */
- /* {{{ proto public mixed ReflectionMethod::invokeArgs(mixed object, array args)
- Invokes the function and pass its arguments as array. */
- ZEND_METHOD(reflection_method, invokeArgs)
- {
- zval *retval_ptr;
- zval ***params;
- zval *object;
- reflection_object *intern;
- zend_function *mptr;
- int argc;
- int result;
- zend_fcall_info fci;
- zend_fcall_info_cache fcc;
- zend_class_entry *obj_ce;
- zval *param_array;
- METHOD_NOTSTATIC(reflection_method_ptr);
- GET_REFLECTION_OBJECT_PTR(mptr);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o!a", &object, ¶m_array) == FAILURE) {
- return;
- }
- if ((!(mptr->common.fn_flags & ZEND_ACC_PUBLIC)
- || (mptr->common.fn_flags & ZEND_ACC_ABSTRACT))
- && intern->ignore_visibility == 0)
- {
- if (mptr->common.fn_flags & ZEND_ACC_ABSTRACT) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Trying to invoke abstract method %s::%s()",
- mptr->common.scope->name, mptr->common.function_name);
- } else {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Trying to invoke %s method %s::%s() from scope %s",
- mptr->common.fn_flags & ZEND_ACC_PROTECTED ? "protected" : "private",
- mptr->common.scope->name, mptr->common.function_name,
- Z_OBJCE_P(getThis())->name);
- }
- return;
- }
- argc = zend_hash_num_elements(Z_ARRVAL_P(param_array));
- params = safe_emalloc(sizeof(zval **), argc, 0);
- zend_hash_apply_with_argument(Z_ARRVAL_P(param_array), (apply_func_arg_t)_zval_array_to_c_array, ¶ms TSRMLS_CC);
- params -= argc;
- /* In case this is a static method, we should'nt pass an object_ptr
- * (which is used as calling context aka $this). We can thus ignore the
- * first parameter.
- *
- * Else, we verify that the given object is an instance of the class.
- */
- if (mptr->common.fn_flags & ZEND_ACC_STATIC) {
- object = NULL;
- obj_ce = mptr->common.scope;
- } else {
- if (!object) {
- efree(params);
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Trying to invoke non static method %s::%s() without an object",
- mptr->common.scope->name, mptr->common.function_name);
- return;
- }
- obj_ce = Z_OBJCE_P(object);
- if (!instanceof_function(obj_ce, mptr->common.scope TSRMLS_CC)) {
- efree(params);
- _DO_THROW("Given object is not an instance of the class this method was declared in");
- /* Returns from this function */
- }
- }
- fci.size = sizeof(fci);
- fci.function_table = NULL;
- fci.function_name = NULL;
- fci.symbol_table = NULL;
- fci.object_ptr = object;
- fci.retval_ptr_ptr = &retval_ptr;
- fci.param_count = argc;
- fci.params = params;
- fci.no_separation = 1;
- fcc.initialized = 1;
- fcc.function_handler = mptr;
- fcc.calling_scope = obj_ce;
- fcc.called_scope = intern->ce;
- fcc.object_ptr = object;
-
- /*
- * Copy the zend_function when calling via handler (e.g. Closure::__invoke())
- */
- if (mptr->type == ZEND_INTERNAL_FUNCTION &&
- (mptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0) {
- fcc.function_handler = _copy_function(mptr TSRMLS_CC);
- }
- result = zend_call_function(&fci, &fcc TSRMLS_CC);
- efree(params);
- if (result == FAILURE) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Invocation of method %s::%s() failed", mptr->common.scope->name, mptr->common.function_name);
- return;
- }
- if (retval_ptr) {
- COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr);
- }
- }
- /* }}} */
- /* {{{ proto public bool ReflectionMethod::isFinal()
- Returns whether this method is final */
- ZEND_METHOD(reflection_method, isFinal)
- {
- _function_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_FINAL);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionMethod::isAbstract()
- Returns whether this method is abstract */
- ZEND_METHOD(reflection_method, isAbstract)
- {
- _function_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_ABSTRACT);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionMethod::isPublic()
- Returns whether this method is public */
- ZEND_METHOD(reflection_method, isPublic)
- {
- _function_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PUBLIC);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionMethod::isPrivate()
- Returns whether this method is private */
- ZEND_METHOD(reflection_method, isPrivate)
- {
- _function_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PRIVATE);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionMethod::isProtected()
- Returns whether this method is protected */
- ZEND_METHOD(reflection_method, isProtected)
- {
- _function_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PROTECTED);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionMethod::isStatic()
- Returns whether this method is static */
- ZEND_METHOD(reflection_method, isStatic)
- {
- _function_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_STATIC);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionFunction::isDeprecated()
- Returns whether this function is deprecated */
- ZEND_METHOD(reflection_function, isDeprecated)
- {
- _function_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_DEPRECATED);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionFunction::isGenerator()
- Returns whether this function is a generator */
- ZEND_METHOD(reflection_function, isGenerator)
- {
- _function_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_GENERATOR);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionFunction::isVariadic()
- Returns whether this function is variadic */
- ZEND_METHOD(reflection_function, isVariadic)
- {
- _function_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_VARIADIC);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionFunction::inNamespace()
- Returns whether this function is defined in namespace */
- ZEND_METHOD(reflection_function, inNamespace)
- {
- zval **name;
- const char *backslash;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- if (zend_hash_find(Z_OBJPROP_P(getThis()), "name", sizeof("name"), (void **) &name) == FAILURE) {
- RETURN_FALSE;
- }
- if (Z_TYPE_PP(name) == IS_STRING
- && (backslash = zend_memrchr(Z_STRVAL_PP(name), '\\', Z_STRLEN_PP(name)))
- && backslash > Z_STRVAL_PP(name))
- {
- RETURN_TRUE;
- }
- RETURN_FALSE;
- }
- /* }}} */
- /* {{{ proto public string ReflectionFunction::getNamespaceName()
- Returns the name of namespace where this function is defined */
- ZEND_METHOD(reflection_function, getNamespaceName)
- {
- zval **name;
- const char *backslash;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- if (zend_hash_find(Z_OBJPROP_P(getThis()), "name", sizeof("name"), (void **) &name) == FAILURE) {
- RETURN_FALSE;
- }
- if (Z_TYPE_PP(name) == IS_STRING
- && (backslash = zend_memrchr(Z_STRVAL_PP(name), '\\', Z_STRLEN_PP(name)))
- && backslash > Z_STRVAL_PP(name))
- {
- RETURN_STRINGL(Z_STRVAL_PP(name), backslash - Z_STRVAL_PP(name), 1);
- }
- RETURN_EMPTY_STRING();
- }
- /* }}} */
- /* {{{ proto public string ReflectionFunction::getShortName()
- Returns the short name of the function (without namespace part) */
- ZEND_METHOD(reflection_function, getShortName)
- {
- zval **name;
- const char *backslash;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- if (zend_hash_find(Z_OBJPROP_P(getThis()), "name", sizeof("name"), (void **) &name) == FAILURE) {
- RETURN_FALSE;
- }
- if (Z_TYPE_PP(name) == IS_STRING
- && (backslash = zend_memrchr(Z_STRVAL_PP(name), '\\', Z_STRLEN_PP(name)))
- && backslash > Z_STRVAL_PP(name))
- {
- RETURN_STRINGL(backslash + 1, Z_STRLEN_PP(name) - (backslash - Z_STRVAL_PP(name) + 1), 1);
- }
- RETURN_ZVAL(*name, 1, 0);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionMethod::isConstructor()
- Returns whether this method is the constructor */
- ZEND_METHOD(reflection_method, isConstructor)
- {
- reflection_object *intern;
- zend_function *mptr;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(mptr);
- /* we need to check if the ctor is the ctor of the class level we we
- * looking at since we might be looking at an inherited old style ctor
- * defined in base class. */
- RETURN_BOOL(mptr->common.fn_flags & ZEND_ACC_CTOR && intern->ce->constructor && intern->ce->constructor->common.scope == mptr->common.scope);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionMethod::isDestructor()
- Returns whether this method is static */
- ZEND_METHOD(reflection_method, isDestructor)
- {
- reflection_object *intern;
- zend_function *mptr;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(mptr);
- RETURN_BOOL(mptr->common.fn_flags & ZEND_ACC_DTOR);
- }
- /* }}} */
- /* {{{ proto public int ReflectionMethod::getModifiers()
- Returns a bitfield of the access modifiers for this method */
- ZEND_METHOD(reflection_method, getModifiers)
- {
- reflection_object *intern;
- zend_function *mptr;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(mptr);
- RETURN_LONG(mptr->common.fn_flags);
- }
- /* }}} */
- /* {{{ proto public ReflectionClass ReflectionMethod::getDeclaringClass()
- Get the declaring class */
- ZEND_METHOD(reflection_method, getDeclaringClass)
- {
- reflection_object *intern;
- zend_function *mptr;
- METHOD_NOTSTATIC(reflection_method_ptr);
- GET_REFLECTION_OBJECT_PTR(mptr);
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- zend_reflection_class_factory(mptr->common.scope, return_value TSRMLS_CC);
- }
- /* }}} */
- /* {{{ proto public ReflectionClass ReflectionMethod::getPrototype()
- Get the prototype */
- ZEND_METHOD(reflection_method, getPrototype)
- {
- reflection_object *intern;
- zend_function *mptr;
- METHOD_NOTSTATIC(reflection_method_ptr);
- GET_REFLECTION_OBJECT_PTR(mptr);
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- if (!mptr->common.prototype) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Method %s::%s does not have a prototype", intern->ce->name, mptr->common.function_name);
- return;
- }
- reflection_method_factory(mptr->common.prototype->common.scope, mptr->common.prototype, NULL, return_value TSRMLS_CC);
- }
- /* }}} */
- /* {{{ proto public void ReflectionMethod::setAccessible(bool visible)
- Sets whether non-public methods can be invoked */
- ZEND_METHOD(reflection_method, setAccessible)
- {
- reflection_object *intern;
- zend_bool visible;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &visible) == FAILURE) {
- return;
- }
- intern = (reflection_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
- if (intern == NULL) {
- return;
- }
- intern->ignore_visibility = visible;
- }
- /* }}} */
- /* {{{ proto public static mixed ReflectionClass::export(mixed argument [, bool return]) throws ReflectionException
- Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */
- ZEND_METHOD(reflection_class, export)
- {
- _reflection_export(INTERNAL_FUNCTION_PARAM_PASSTHRU, reflection_class_ptr, 1);
- }
- /* }}} */
- /* {{{ reflection_class_object_ctor */
- static void reflection_class_object_ctor(INTERNAL_FUNCTION_PARAMETERS, int is_object)
- {
- zval *argument;
- zval *object;
- zval *classname;
- reflection_object *intern;
- zend_class_entry **ce;
- if (is_object) {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &argument) == FAILURE) {
- return;
- }
- } else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &argument) == FAILURE) {
- return;
- }
- }
- object = getThis();
- intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC);
- if (intern == NULL) {
- return;
- }
- if (Z_TYPE_P(argument) == IS_OBJECT) {
- MAKE_STD_ZVAL(classname);
- ZVAL_STRINGL(classname, Z_OBJCE_P(argument)->name, Z_OBJCE_P(argument)->name_length, 1);
- reflection_update_property(object, "name", classname);
- intern->ptr = Z_OBJCE_P(argument);
- if (is_object) {
- intern->obj = argument;
- zval_add_ref(&argument);
- }
- } else {
- convert_to_string_ex(&argument);
- if (zend_lookup_class(Z_STRVAL_P(argument), Z_STRLEN_P(argument), &ce TSRMLS_CC) == FAILURE) {
- if (!EG(exception)) {
- zend_throw_exception_ex(reflection_exception_ptr, -1 TSRMLS_CC, "Class %s does not exist", Z_STRVAL_P(argument));
- }
- return;
- }
- MAKE_STD_ZVAL(classname);
- ZVAL_STRINGL(classname, (*ce)->name, (*ce)->name_length, 1);
- reflection_update_property(object, "name", classname);
- intern->ptr = *ce;
- }
- intern->ref_type = REF_TYPE_OTHER;
- }
- /* }}} */
- /* {{{ proto public void ReflectionClass::__construct(mixed argument) throws ReflectionException
- Constructor. Takes a string or an instance as an argument */
- ZEND_METHOD(reflection_class, __construct)
- {
- reflection_class_object_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
- }
- /* }}} */
- /* {{{ add_class_vars */
- static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value TSRMLS_DC)
- {
- HashPosition pos;
- zend_property_info *prop_info;
- zval *prop, *prop_copy;
- char *key;
- uint key_len;
- ulong num_index;
- zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos);
- while (zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop_info, &pos) == SUCCESS) {
- zend_hash_get_current_key_ex(&ce->properties_info, &key, &key_len, &num_index, 0, &pos);
- zend_hash_move_forward_ex(&ce->properties_info, &pos);
- if (((prop_info->flags & ZEND_ACC_SHADOW) &&
- prop_info->ce != ce) ||
- ((prop_info->flags & ZEND_ACC_PROTECTED) &&
- !zend_check_protected(prop_info->ce, ce)) ||
- ((prop_info->flags & ZEND_ACC_PRIVATE) &&
- prop_info->ce != ce)) {
- continue;
- }
- prop = NULL;
- if (prop_info->offset >= 0) {
- if (statics && (prop_info->flags & ZEND_ACC_STATIC) != 0) {
- prop = ce->default_static_members_table[prop_info->offset];
- } else if (!statics && (prop_info->flags & ZEND_ACC_STATIC) == 0) {
- prop = ce->default_properties_table[prop_info->offset];
- }
- }
- if (!prop) {
- continue;
- }
- /* copy: enforce read only access */
- ALLOC_ZVAL(prop_copy);
- *prop_copy = *prop;
- zval_copy_ctor(prop_copy);
- INIT_PZVAL(prop_copy);
- /* this is necessary to make it able to work with default array
- * properties, returned to user */
- if (IS_CONSTANT_TYPE(Z_TYPE_P(prop_copy))) {
- zval_update_constant(&prop_copy, 1 TSRMLS_CC);
- }
- add_assoc_zval(return_value, key, prop_copy);
- }
- }
- /* }}} */
- /* {{{ proto public array ReflectionClass::getStaticProperties()
- Returns an associative array containing all static property values of the class */
- ZEND_METHOD(reflection_class, getStaticProperties)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- zend_update_class_constants(ce TSRMLS_CC);
- array_init(return_value);
- add_class_vars(ce, 1, return_value TSRMLS_CC);
- }
- /* }}} */
- /* {{{ proto public mixed ReflectionClass::getStaticPropertyValue(string name [, mixed default])
- Returns the value of a static property */
- ZEND_METHOD(reflection_class, getStaticPropertyValue)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- char *name;
- int name_len;
- zval **prop, *def_value = NULL;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z", &name, &name_len, &def_value) == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- zend_update_class_constants(ce TSRMLS_CC);
- prop = zend_std_get_static_property(ce, name, name_len, 1, NULL TSRMLS_CC);
- if (!prop) {
- if (def_value) {
- RETURN_ZVAL(def_value, 1, 0);
- } else {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Class %s does not have a property named %s", ce->name, name);
- }
- return;
- } else {
- RETURN_ZVAL(*prop, 1, 0);
- }
- }
- /* }}} */
- /* {{{ proto public void ReflectionClass::setStaticPropertyValue($name, $value)
- Sets the value of a static property */
- ZEND_METHOD(reflection_class, setStaticPropertyValue)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- char *name;
- int name_len;
- zval **variable_ptr, *value;
- int refcount;
- zend_uchar is_ref;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &name_len, &value) == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- zend_update_class_constants(ce TSRMLS_CC);
- variable_ptr = zend_std_get_static_property(ce, name, name_len, 1, NULL TSRMLS_CC);
- if (!variable_ptr) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Class %s does not have a property named %s", ce->name, name);
- return;
- }
- refcount = Z_REFCOUNT_PP(variable_ptr);
- is_ref = Z_ISREF_PP(variable_ptr);
- zval_dtor(*variable_ptr);
- **variable_ptr = *value;
- zval_copy_ctor(*variable_ptr);
- Z_SET_REFCOUNT_PP(variable_ptr, refcount);
- Z_SET_ISREF_TO_PP(variable_ptr, is_ref);
- }
- /* }}} */
- /* {{{ proto public array ReflectionClass::getDefaultProperties()
- Returns an associative array containing copies of all default property values of the class */
- ZEND_METHOD(reflection_class, getDefaultProperties)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- array_init(return_value);
- zend_update_class_constants(ce TSRMLS_CC);
- add_class_vars(ce, 1, return_value TSRMLS_CC);
- add_class_vars(ce, 0, return_value TSRMLS_CC);
- }
- /* }}} */
- /* {{{ proto public string ReflectionClass::__toString()
- Returns a string representation */
- ZEND_METHOD(reflection_class, __toString)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- string str;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- string_init(&str);
- _class_string(&str, ce, intern->obj, "" TSRMLS_CC);
- RETURN_STRINGL(str.string, str.len - 1, 0);
- }
- /* }}} */
- /* {{{ proto public string ReflectionClass::getName()
- Returns the class' name */
- ZEND_METHOD(reflection_class, getName)
- {
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- _default_get_entry(getThis(), "name", sizeof("name"), return_value TSRMLS_CC);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionClass::isInternal()
- Returns whether this class is an internal class */
- ZEND_METHOD(reflection_class, isInternal)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- RETURN_BOOL(ce->type == ZEND_INTERNAL_CLASS);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionClass::isUserDefined()
- Returns whether this class is user-defined */
- ZEND_METHOD(reflection_class, isUserDefined)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- RETURN_BOOL(ce->type == ZEND_USER_CLASS);
- }
- /* }}} */
- /* {{{ proto public string ReflectionClass::getFileName()
- Returns the filename of the file this class was declared in */
- ZEND_METHOD(reflection_class, getFileName)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- if (ce->type == ZEND_USER_CLASS) {
- RETURN_STRING(ce->info.user.filename, 1);
- }
- RETURN_FALSE;
- }
- /* }}} */
- /* {{{ proto public int ReflectionClass::getStartLine()
- Returns the line this class' declaration starts at */
- ZEND_METHOD(reflection_class, getStartLine)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- if (ce->type == ZEND_USER_FUNCTION) {
- RETURN_LONG(ce->info.user.line_start);
- }
- RETURN_FALSE;
- }
- /* }}} */
- /* {{{ proto public int ReflectionClass::getEndLine()
- Returns the line this class' declaration ends at */
- ZEND_METHOD(reflection_class, getEndLine)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- if (ce->type == ZEND_USER_CLASS) {
- RETURN_LONG(ce->info.user.line_end);
- }
- RETURN_FALSE;
- }
- /* }}} */
- /* {{{ proto public string ReflectionClass::getDocComment()
- Returns the doc comment for this class */
- ZEND_METHOD(reflection_class, getDocComment)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- if (ce->type == ZEND_USER_CLASS && ce->info.user.doc_comment) {
- RETURN_STRINGL(ce->info.user.doc_comment, ce->info.user.doc_comment_len, 1);
- }
- RETURN_FALSE;
- }
- /* }}} */
- /* {{{ proto public ReflectionMethod ReflectionClass::getConstructor()
- Returns the class' constructor if there is one, NULL otherwise */
- ZEND_METHOD(reflection_class, getConstructor)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- if (ce->constructor) {
- reflection_method_factory(ce, ce->constructor, NULL, return_value TSRMLS_CC);
- } else {
- RETURN_NULL();
- }
- }
- /* }}} */
- /* {{{ proto public bool ReflectionClass::hasMethod(string name)
- Returns whether a method exists or not */
- ZEND_METHOD(reflection_class, hasMethod)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- char *name, *lc_name;
- int name_len;
- METHOD_NOTSTATIC(reflection_class_ptr);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- lc_name = zend_str_tolower_dup(name, name_len);
- if ((ce == zend_ce_closure && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1)
- && memcmp(lc_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0)
- || zend_hash_exists(&ce->function_table, lc_name, name_len + 1)) {
- efree(lc_name);
- RETURN_TRUE;
- } else {
- efree(lc_name);
- RETURN_FALSE;
- }
- }
- /* }}} */
- /* {{{ proto public ReflectionMethod ReflectionClass::getMethod(string name) throws ReflectionException
- Returns the class' method specified by its name */
- ZEND_METHOD(reflection_class, getMethod)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- zend_function *mptr;
- zval obj_tmp;
- char *name, *lc_name;
- int name_len;
- METHOD_NOTSTATIC(reflection_class_ptr);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- lc_name = zend_str_tolower_dup(name, name_len);
- if (ce == zend_ce_closure && intern->obj && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1)
- && memcmp(lc_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0
- && (mptr = zend_get_closure_invoke_method(intern->obj TSRMLS_CC)) != NULL)
- {
- /* don't assign closure_object since we only reflect the invoke handler
- method and not the closure definition itself */
- reflection_method_factory(ce, mptr, NULL, return_value TSRMLS_CC);
- efree(lc_name);
- } else if (ce == zend_ce_closure && !intern->obj && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1)
- && memcmp(lc_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0
- && object_init_ex(&obj_tmp, ce) == SUCCESS && (mptr = zend_get_closure_invoke_method(&obj_tmp TSRMLS_CC)) != NULL) {
- /* don't assign closure_object since we only reflect the invoke handler
- method and not the closure definition itself */
- reflection_method_factory(ce, mptr, NULL, return_value TSRMLS_CC);
- zval_dtor(&obj_tmp);
- efree(lc_name);
- } else if (zend_hash_find(&ce->function_table, lc_name, name_len + 1, (void**) &mptr) == SUCCESS) {
- reflection_method_factory(ce, mptr, NULL, return_value TSRMLS_CC);
- efree(lc_name);
- } else {
- efree(lc_name);
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Method %s does not exist", name);
- return;
- }
- }
- /* }}} */
- /* {{{ _addmethod */
- static void _addmethod(zend_function *mptr, zend_class_entry *ce, zval *retval, long filter, zval *obj TSRMLS_DC)
- {
- zval *method;
- uint len = strlen(mptr->common.function_name);
- zend_function *closure;
- if (mptr->common.fn_flags & filter) {
- ALLOC_ZVAL(method);
- if (ce == zend_ce_closure && obj && (len == sizeof(ZEND_INVOKE_FUNC_NAME)-1)
- && memcmp(mptr->common.function_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0
- && (closure = zend_get_closure_invoke_method(obj TSRMLS_CC)) != NULL)
- {
- mptr = closure;
- }
- /* don't assign closure_object since we only reflect the invoke handler
- method and not the closure definition itself, even if we have a
- closure */
- reflection_method_factory(ce, mptr, NULL, method TSRMLS_CC);
- add_next_index_zval(retval, method);
- }
- }
- /* }}} */
- /* {{{ _addmethod */
- static int _addmethod_va(zend_function *mptr TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
- {
- zend_class_entry *ce = *va_arg(args, zend_class_entry**);
- zval *retval = va_arg(args, zval*);
- long filter = va_arg(args, long);
- zval *obj = va_arg(args, zval *);
- _addmethod(mptr, ce, retval, filter, obj TSRMLS_CC);
- return ZEND_HASH_APPLY_KEEP;
- }
- /* }}} */
- /* {{{ proto public ReflectionMethod[] ReflectionClass::getMethods([long $filter])
- Returns an array of this class' methods */
- ZEND_METHOD(reflection_class, getMethods)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- long filter = 0;
- int argc = ZEND_NUM_ARGS();
- METHOD_NOTSTATIC(reflection_class_ptr);
- if (argc) {
- if (zend_parse_parameters(argc TSRMLS_CC, "|l", &filter) == FAILURE) {
- return;
- }
- } else {
- /* No parameters given, default to "return all" */
- filter = ZEND_ACC_PPP_MASK | ZEND_ACC_ABSTRACT | ZEND_ACC_FINAL | ZEND_ACC_STATIC;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- array_init(return_value);
- zend_hash_apply_with_arguments(&ce->function_table TSRMLS_CC, (apply_func_args_t) _addmethod_va, 4, &ce, return_value, filter, intern->obj);
- if (intern->obj && instanceof_function(ce, zend_ce_closure TSRMLS_CC)) {
- zend_function *closure = zend_get_closure_invoke_method(intern->obj TSRMLS_CC);
- if (closure) {
- _addmethod(closure, ce, return_value, filter, intern->obj TSRMLS_CC);
- _free_function(closure TSRMLS_CC);
- }
- }
- }
- /* }}} */
- /* {{{ proto public bool ReflectionClass::hasProperty(string name)
- Returns whether a property exists or not */
- ZEND_METHOD(reflection_class, hasProperty)
- {
- reflection_object *intern;
- zend_property_info *property_info;
- zend_class_entry *ce;
- char *name;
- int name_len;
- zval *property;
- METHOD_NOTSTATIC(reflection_class_ptr);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- if (zend_hash_find(&ce->properties_info, name, name_len+1, (void **) &property_info) == SUCCESS) {
- if (property_info->flags & ZEND_ACC_SHADOW) {
- RETURN_FALSE;
- }
- RETURN_TRUE;
- } else {
- if (intern->obj && Z_OBJ_HANDLER_P(intern->obj, has_property)) {
- MAKE_STD_ZVAL(property);
- ZVAL_STRINGL(property, name, name_len, 1);
- if (Z_OBJ_HANDLER_P(intern->obj, has_property)(intern->obj, property, 2, 0 TSRMLS_CC)) {
- zval_ptr_dtor(&property);
- RETURN_TRUE;
- }
- zval_ptr_dtor(&property);
- }
- RETURN_FALSE;
- }
- }
- /* }}} */
- /* {{{ proto public ReflectionProperty ReflectionClass::getProperty(string name) throws ReflectionException
- Returns the class' property specified by its name */
- ZEND_METHOD(reflection_class, getProperty)
- {
- reflection_object *intern;
- zend_class_entry *ce, **pce;
- zend_property_info *property_info;
- char *name, *tmp, *classname;
- int name_len, classname_len;
- METHOD_NOTSTATIC(reflection_class_ptr);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- if (zend_hash_find(&ce->properties_info, name, name_len + 1, (void**) &property_info) == SUCCESS) {
- if ((property_info->flags & ZEND_ACC_SHADOW) == 0) {
- reflection_property_factory(ce, property_info, return_value TSRMLS_CC);
- return;
- }
- } else if (intern->obj) {
- /* Check for dynamic properties */
- if (zend_hash_exists(Z_OBJ_HT_P(intern->obj)->get_properties(intern->obj TSRMLS_CC), name, name_len+1)) {
- zend_property_info property_info_tmp;
- property_info_tmp.flags = ZEND_ACC_IMPLICIT_PUBLIC;
- property_info_tmp.name = estrndup(name, name_len);
- property_info_tmp.name_length = name_len;
- property_info_tmp.h = zend_get_hash_value(name, name_len+1);
- property_info_tmp.doc_comment = NULL;
- property_info_tmp.ce = ce;
- reflection_property_factory(ce, &property_info_tmp, return_value TSRMLS_CC);
- intern = (reflection_object *) zend_object_store_get_object(return_value TSRMLS_CC);
- intern->ref_type = REF_TYPE_DYNAMIC_PROPERTY;
- return;
- }
- }
- if ((tmp = strstr(name, "::")) != NULL) {
- classname_len = tmp - name;
- classname = zend_str_tolower_dup(name, classname_len);
- classname[classname_len] = '\0';
- name_len = name_len - (classname_len + 2);
- name = tmp + 2;
- if (zend_lookup_class(classname, classname_len, &pce TSRMLS_CC) == FAILURE) {
- if (!EG(exception)) {
- zend_throw_exception_ex(reflection_exception_ptr, -1 TSRMLS_CC, "Class %s does not exist", classname);
- }
- efree(classname);
- return;
- }
- efree(classname);
- if (!instanceof_function(ce, *pce TSRMLS_CC)) {
- zend_throw_exception_ex(reflection_exception_ptr, -1 TSRMLS_CC, "Fully qualified property name %s::%s does not specify a base class of %s", (*pce)->name, name, ce->name);
- return;
- }
- ce = *pce;
- if (zend_hash_find(&ce->properties_info, name, name_len + 1, (void**) &property_info) == SUCCESS && (property_info->flags & ZEND_ACC_SHADOW) == 0) {
- reflection_property_factory(ce, property_info, return_value TSRMLS_CC);
- return;
- }
- }
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Property %s does not exist", name);
- }
- /* }}} */
- /* {{{ _addproperty */
- static int _addproperty(zend_property_info *pptr TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
- {
- zval *property;
- zend_class_entry *ce = *va_arg(args, zend_class_entry**);
- zval *retval = va_arg(args, zval*);
- long filter = va_arg(args, long);
- if (pptr->flags & ZEND_ACC_SHADOW) {
- return 0;
- }
- if (pptr->flags & filter) {
- ALLOC_ZVAL(property);
- reflection_property_factory(ce, pptr, property TSRMLS_CC);
- add_next_index_zval(retval, property);
- }
- return 0;
- }
- /* }}} */
- /* {{{ _adddynproperty */
- static int _adddynproperty(zval **pptr TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
- {
- zval *property;
- zend_class_entry *ce = *va_arg(args, zend_class_entry**);
- zval *retval = va_arg(args, zval*), member;
- /* under some circumstances, the properties hash table may contain numeric
- * properties (e.g. when casting from array). This is a WONT FIX bug, at
- * least for the moment. Ignore these */
- if (hash_key->nKeyLength == 0) {
- return 0;
- }
- if (hash_key->arKey[0] == '\0') {
- return 0; /* non public cannot be dynamic */
- }
- ZVAL_STRINGL(&member, hash_key->arKey, hash_key->nKeyLength-1, 0);
- if (zend_get_property_info(ce, &member, 1 TSRMLS_CC) == &EG(std_property_info)) {
- MAKE_STD_ZVAL(property);
- EG(std_property_info).flags = ZEND_ACC_IMPLICIT_PUBLIC;
- reflection_property_factory(ce, &EG(std_property_info), property TSRMLS_CC);
- add_next_index_zval(retval, property);
- }
- return 0;
- }
- /* }}} */
- /* {{{ proto public ReflectionProperty[] ReflectionClass::getProperties([long $filter])
- Returns an array of this class' properties */
- ZEND_METHOD(reflection_class, getProperties)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- long filter = 0;
- int argc = ZEND_NUM_ARGS();
- METHOD_NOTSTATIC(reflection_class_ptr);
- if (argc) {
- if (zend_parse_parameters(argc TSRMLS_CC, "|l", &filter) == FAILURE) {
- return;
- }
- } else {
- /* No parameters given, default to "return all" */
- filter = ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- array_init(return_value);
- zend_hash_apply_with_arguments(&ce->properties_info TSRMLS_CC, (apply_func_args_t) _addproperty, 3, &ce, return_value, filter);
- if (intern->obj && (filter & ZEND_ACC_PUBLIC) != 0 && Z_OBJ_HT_P(intern->obj)->get_properties) {
- HashTable *properties = Z_OBJ_HT_P(intern->obj)->get_properties(intern->obj TSRMLS_CC);
- zend_hash_apply_with_arguments(properties TSRMLS_CC, (apply_func_args_t) _adddynproperty, 2, &ce, return_value);
- }
- }
- /* }}} */
- /* {{{ proto public bool ReflectionClass::hasConstant(string name)
- Returns whether a constant exists or not */
- ZEND_METHOD(reflection_class, hasConstant)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- char *name;
- int name_len;
- METHOD_NOTSTATIC(reflection_class_ptr);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- if (zend_hash_exists(&ce->constants_table, name, name_len + 1)) {
- RETURN_TRUE;
- } else {
- RETURN_FALSE;
- }
- }
- /* }}} */
- /* {{{ proto public array ReflectionClass::getConstants()
- Returns an associative array containing this class' constants and their values */
- ZEND_METHOD(reflection_class, getConstants)
- {
- zval *tmp_copy;
- reflection_object *intern;
- zend_class_entry *ce;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- array_init(return_value);
- zend_hash_apply_with_argument(&ce->constants_table, (apply_func_arg_t)zval_update_constant_inline_change, ce TSRMLS_CC);
- zend_hash_copy(Z_ARRVAL_P(return_value), &ce->constants_table, (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(zval *));
- }
- /* }}} */
- /* {{{ proto public mixed ReflectionClass::getConstant(string name)
- Returns the class' constant specified by its name */
- ZEND_METHOD(reflection_class, getConstant)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- zval **value;
- char *name;
- int name_len;
- METHOD_NOTSTATIC(reflection_class_ptr);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- zend_hash_apply_with_argument(&ce->constants_table, (apply_func_arg_t)zval_update_constant_inline_change, ce TSRMLS_CC);
- if (zend_hash_find(&ce->constants_table, name, name_len + 1, (void **) &value) == FAILURE) {
- RETURN_FALSE;
- }
- MAKE_COPY_ZVAL(value, return_value);
- }
- /* }}} */
- /* {{{ _class_check_flag */
- static void _class_check_flag(INTERNAL_FUNCTION_PARAMETERS, int mask)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- RETVAL_BOOL(ce->ce_flags & mask);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionClass::isInstantiable()
- Returns whether this class is instantiable */
- ZEND_METHOD(reflection_class, isInstantiable)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- if (ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS)) {
- RETURN_FALSE;
- }
- /* Basically, the class is instantiable. Though, if there is a constructor
- * and it is not publicly accessible, it isn't! */
- if (!ce->constructor) {
- RETURN_TRUE;
- }
- RETURN_BOOL(ce->constructor->common.fn_flags & ZEND_ACC_PUBLIC);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionClass::isCloneable()
- Returns whether this class is cloneable */
- ZEND_METHOD(reflection_class, isCloneable)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- zval obj;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- if (ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS)) {
- RETURN_FALSE;
- }
- if (intern->obj) {
- if (ce->clone) {
- RETURN_BOOL(ce->clone->common.fn_flags & ZEND_ACC_PUBLIC);
- } else {
- RETURN_BOOL(Z_OBJ_HANDLER_P(intern->obj, clone_obj) != NULL);
- }
- } else {
- if (ce->clone) {
- RETURN_BOOL(ce->clone->common.fn_flags & ZEND_ACC_PUBLIC);
- } else {
- object_init_ex(&obj, ce);
- RETVAL_BOOL(Z_OBJ_HANDLER(obj, clone_obj) != NULL);
- zval_dtor(&obj);
- }
- }
- }
- /* }}} */
- /* {{{ proto public bool ReflectionClass::isInterface()
- Returns whether this is an interface or a class */
- ZEND_METHOD(reflection_class, isInterface)
- {
- _class_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_INTERFACE);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionClass::isTrait()
- Returns whether this is a trait */
- ZEND_METHOD(reflection_class, isTrait)
- {
- _class_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_TRAIT & ~ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionClass::isFinal()
- Returns whether this class is final */
- ZEND_METHOD(reflection_class, isFinal)
- {
- _class_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_FINAL_CLASS);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionClass::isAbstract()
- Returns whether this class is abstract */
- ZEND_METHOD(reflection_class, isAbstract)
- {
- _class_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
- }
- /* }}} */
- /* {{{ proto public int ReflectionClass::getModifiers()
- Returns a bitfield of the access modifiers for this class */
- ZEND_METHOD(reflection_class, getModifiers)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- RETURN_LONG(ce->ce_flags);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionClass::isInstance(stdclass object)
- Returns whether the given object is an instance of this class */
- ZEND_METHOD(reflection_class, isInstance)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- zval *object;
- METHOD_NOTSTATIC(reflection_class_ptr);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &object) == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- RETURN_BOOL(HAS_CLASS_ENTRY(*object) && instanceof_function(Z_OBJCE_P(object), ce TSRMLS_CC));
- }
- /* }}} */
- /* {{{ proto public stdclass ReflectionClass::newInstance(mixed* args, ...)
- Returns an instance of this class */
- ZEND_METHOD(reflection_class, newInstance)
- {
- zval *retval_ptr = NULL;
- reflection_object *intern;
- zend_class_entry *ce, *old_scope;
- zend_function *constructor;
- METHOD_NOTSTATIC(reflection_class_ptr);
- GET_REFLECTION_OBJECT_PTR(ce);
- object_init_ex(return_value, ce);
- old_scope = EG(scope);
- EG(scope) = ce;
- constructor = Z_OBJ_HT_P(return_value)->get_constructor(return_value TSRMLS_CC);
- EG(scope) = old_scope;
- /* Run the constructor if there is one */
- if (constructor) {
- zval ***params = NULL;
- int num_args = 0;
- zend_fcall_info fci;
- zend_fcall_info_cache fcc;
- if (!(constructor->common.fn_flags & ZEND_ACC_PUBLIC)) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Access to non-public constructor of class %s", ce->name);
- zval_dtor(return_value);
- RETURN_NULL();
- }
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "*", ¶ms, &num_args) == FAILURE) {
- if (params) {
- efree(params);
- }
- zval_dtor(return_value);
- RETURN_FALSE;
- }
- fci.size = sizeof(fci);
- fci.function_table = EG(function_table);
- fci.function_name = NULL;
- fci.symbol_table = NULL;
- fci.object_ptr = return_value;
- fci.retval_ptr_ptr = &retval_ptr;
- fci.param_count = num_args;
- fci.params = params;
- fci.no_separation = 1;
- fcc.initialized = 1;
- fcc.function_handler = constructor;
- fcc.calling_scope = EG(scope);
- fcc.called_scope = Z_OBJCE_P(return_value);
- fcc.object_ptr = return_value;
- if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) {
- if (params) {
- efree(params);
- }
- if (retval_ptr) {
- zval_ptr_dtor(&retval_ptr);
- }
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invocation of %s's constructor failed", ce->name);
- zval_dtor(return_value);
- RETURN_NULL();
- }
- if (retval_ptr) {
- zval_ptr_dtor(&retval_ptr);
- }
- if (params) {
- efree(params);
- }
- } else if (ZEND_NUM_ARGS()) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ce->name);
- }
- }
- /* }}} */
- /* {{{ proto public stdclass ReflectionClass::newInstanceWithoutConstructor()
- Returns an instance of this class without invoking its constructor */
- ZEND_METHOD(reflection_class, newInstanceWithoutConstructor)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- METHOD_NOTSTATIC(reflection_class_ptr);
- GET_REFLECTION_OBJECT_PTR(ce);
- if (ce->create_object != NULL && ce->ce_flags & ZEND_ACC_FINAL_CLASS) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s is an internal class marked as final that cannot be instantiated without invoking its constructor", ce->name);
- }
- object_init_ex(return_value, ce);
- }
- /* }}} */
- /* {{{ proto public stdclass ReflectionClass::newInstanceArgs([array args])
- Returns an instance of this class */
- ZEND_METHOD(reflection_class, newInstanceArgs)
- {
- zval *retval_ptr = NULL;
- reflection_object *intern;
- zend_class_entry *ce, *old_scope;
- int argc = 0;
- HashTable *args;
- zend_function *constructor;
- METHOD_NOTSTATIC(reflection_class_ptr);
- GET_REFLECTION_OBJECT_PTR(ce);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|h", &args) == FAILURE) {
- return;
- }
- if (ZEND_NUM_ARGS() > 0) {
- argc = args->nNumOfElements;
- }
- object_init_ex(return_value, ce);
- old_scope = EG(scope);
- EG(scope) = ce;
- constructor = Z_OBJ_HT_P(return_value)->get_constructor(return_value TSRMLS_CC);
- EG(scope) = old_scope;
- /* Run the constructor if there is one */
- if (constructor) {
- zval ***params = NULL;
- zend_fcall_info fci;
- zend_fcall_info_cache fcc;
- if (!(constructor->common.fn_flags & ZEND_ACC_PUBLIC)) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Access to non-public constructor of class %s", ce->name);
- zval_dtor(return_value);
- RETURN_NULL();
- }
- if (argc) {
- params = safe_emalloc(sizeof(zval **), argc, 0);
- zend_hash_apply_with_argument(args, (apply_func_arg_t)_zval_array_to_c_array, ¶ms TSRMLS_CC);
- params -= argc;
- }
- fci.size = sizeof(fci);
- fci.function_table = EG(function_table);
- fci.function_name = NULL;
- fci.symbol_table = NULL;
- fci.object_ptr = return_value;
- fci.retval_ptr_ptr = &retval_ptr;
- fci.param_count = argc;
- fci.params = params;
- fci.no_separation = 1;
- fcc.initialized = 1;
- fcc.function_handler = constructor;
- fcc.calling_scope = EG(scope);
- fcc.called_scope = Z_OBJCE_P(return_value);
- fcc.object_ptr = return_value;
- if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) {
- if (params) {
- efree(params);
- }
- if (retval_ptr) {
- zval_ptr_dtor(&retval_ptr);
- }
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invocation of %s's constructor failed", ce->name);
- zval_dtor(return_value);
- RETURN_NULL();
- }
- if (retval_ptr) {
- zval_ptr_dtor(&retval_ptr);
- }
- if (params) {
- efree(params);
- }
- } else if (argc) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ce->name);
- }
- }
- /* }}} */
- /* {{{ proto public ReflectionClass[] ReflectionClass::getInterfaces()
- Returns an array of interfaces this class implements */
- ZEND_METHOD(reflection_class, getInterfaces)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- /* Return an empty array if this class implements no interfaces */
- array_init(return_value);
- if (ce->num_interfaces) {
- zend_uint i;
- for (i=0; i < ce->num_interfaces; i++) {
- zval *interface;
- ALLOC_ZVAL(interface);
- zend_reflection_class_factory(ce->interfaces[i], interface TSRMLS_CC);
- add_assoc_zval_ex(return_value, ce->interfaces[i]->name, ce->interfaces[i]->name_length + 1, interface);
- }
- }
- }
- /* }}} */
- /* {{{ proto public String[] ReflectionClass::getInterfaceNames()
- Returns an array of names of interfaces this class implements */
- ZEND_METHOD(reflection_class, getInterfaceNames)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- zend_uint i;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- /* Return an empty array if this class implements no interfaces */
- array_init(return_value);
- for (i=0; i < ce->num_interfaces; i++) {
- add_next_index_stringl(return_value, ce->interfaces[i]->name, ce->interfaces[i]->name_length, 1);
- }
- }
- /* }}} */
- /* {{{ proto public ReflectionClass[] ReflectionClass::getTraits()
- Returns an array of traits used by this class */
- ZEND_METHOD(reflection_class, getTraits)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- zend_uint i;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- array_init(return_value);
- for (i=0; i < ce->num_traits; i++) {
- zval *trait;
- ALLOC_ZVAL(trait);
- zend_reflection_class_factory(ce->traits[i], trait TSRMLS_CC);
- add_assoc_zval_ex(return_value, ce->traits[i]->name, ce->traits[i]->name_length + 1, trait);
- }
- }
- /* }}} */
- /* {{{ proto public String[] ReflectionClass::getTraitNames()
- Returns an array of names of traits used by this class */
- ZEND_METHOD(reflection_class, getTraitNames)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- zend_uint i;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- array_init(return_value);
- for (i=0; i < ce->num_traits; i++) {
- add_next_index_stringl(return_value, ce->traits[i]->name, ce->traits[i]->name_length, 1);
- }
- }
- /* }}} */
- /* {{{ proto public arra ReflectionClass::getTraitaliases()
- Returns an array of trait aliases */
- ZEND_METHOD(reflection_class, getTraitAliases)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- array_init(return_value);
- if (ce->trait_aliases) {
- zend_uint i = 0;
- while (ce->trait_aliases[i]) {
- char *method_name;
- int method_name_len;
- zend_trait_method_reference *cur_ref = ce->trait_aliases[i]->trait_method;
- if (ce->trait_aliases[i]->alias) {
- method_name_len = spprintf(&method_name, 0, "%s::%s", cur_ref->ce->name, cur_ref->method_name);
- add_assoc_stringl_ex(return_value, ce->trait_aliases[i]->alias, ce->trait_aliases[i]->alias_len + 1, method_name, method_name_len, 0);
- }
- i++;
- }
- }
- }
- /* }}} */
- /* {{{ proto public ReflectionClass ReflectionClass::getParentClass()
- Returns the class' parent class, or, if none exists, FALSE */
- ZEND_METHOD(reflection_class, getParentClass)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ce);
- if (ce->parent) {
- zend_reflection_class_factory(ce->parent, return_value TSRMLS_CC);
- } else {
- RETURN_FALSE;
- }
- }
- /* }}} */
- /* {{{ proto public bool ReflectionClass::isSubclassOf(string|ReflectionClass class)
- Returns whether this class is a subclass of another class */
- ZEND_METHOD(reflection_class, isSubclassOf)
- {
- reflection_object *intern, *argument;
- zend_class_entry *ce, **pce, *class_ce;
- zval *class_name;
- METHOD_NOTSTATIC(reflection_class_ptr);
- GET_REFLECTION_OBJECT_PTR(ce);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &class_name) == FAILURE) {
- return;
- }
- switch(class_name->type) {
- case IS_STRING:
- if (zend_lookup_class(Z_STRVAL_P(class_name), Z_STRLEN_P(class_name), &pce TSRMLS_CC) == FAILURE) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Class %s does not exist", Z_STRVAL_P(class_name));
- return;
- }
- class_ce = *pce;
- break;
- case IS_OBJECT:
- if (instanceof_function(Z_OBJCE_P(class_name), reflection_class_ptr TSRMLS_CC)) {
- argument = (reflection_object *) zend_object_store_get_object(class_name TSRMLS_CC);
- if (argument == NULL || argument->ptr == NULL) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Failed to retrieve the argument's reflection object");
- /* Bails out */
- }
- class_ce = argument->ptr;
- break;
- }
- /* no break */
- default:
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Parameter one must either be a string or a ReflectionClass object");
- return;
- }
- RETURN_BOOL((ce != class_ce && instanceof_function(ce, class_ce TSRMLS_CC)));
- }
- /* }}} */
- /* {{{ proto public bool ReflectionClass::implementsInterface(string|ReflectionClass interface_name)
- Returns whether this class is a subclass of another class */
- ZEND_METHOD(reflection_class, implementsInterface)
- {
- reflection_object *intern, *argument;
- zend_class_entry *ce, *interface_ce, **pce;
- zval *interface;
- METHOD_NOTSTATIC(reflection_class_ptr);
- GET_REFLECTION_OBJECT_PTR(ce);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &interface) == FAILURE) {
- return;
- }
- switch(interface->type) {
- case IS_STRING:
- if (zend_lookup_class(Z_STRVAL_P(interface), Z_STRLEN_P(interface), &pce TSRMLS_CC) == FAILURE) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Interface %s does not exist", Z_STRVAL_P(interface));
- return;
- }
- interface_ce = *pce;
- break;
- case IS_OBJECT:
- if (instanceof_function(Z_OBJCE_P(interface), reflection_class_ptr TSRMLS_CC)) {
- argument = (reflection_object *) zend_object_store_get_object(interface TSRMLS_CC);
- if (argument == NULL || argument->ptr == NULL) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Failed to retrieve the argument's reflection object");
- /* Bails out */
- }
- interface_ce = argument->ptr;
- break;
- }
- /* no break */
- default:
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Parameter one must either be a string or a ReflectionClass object");
- return;
- }
- if (!(interface_ce->ce_flags & ZEND_ACC_INTERFACE)) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Interface %s is a Class", interface_ce->name);
- return;
- }
- RETURN_BOOL(instanceof_function(ce, interface_ce TSRMLS_CC));
- }
- /* }}} */
- /* {{{ proto public bool ReflectionClass::isIterateable()
- Returns whether this class is iterateable (can be used inside foreach) */
- ZEND_METHOD(reflection_class, isIterateable)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- METHOD_NOTSTATIC(reflection_class_ptr);
- GET_REFLECTION_OBJECT_PTR(ce);
- RETURN_BOOL(ce->get_iterator != NULL);
- }
- /* }}} */
- /* {{{ proto public ReflectionExtension|NULL ReflectionClass::getExtension()
- Returns NULL or the extension the class belongs to */
- ZEND_METHOD(reflection_class, getExtension)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- METHOD_NOTSTATIC(reflection_class_ptr);
- GET_REFLECTION_OBJECT_PTR(ce);
- if ((ce->type == ZEND_INTERNAL_CLASS) && ce->info.internal.module) {
- reflection_extension_factory(return_value, ce->info.internal.module->name TSRMLS_CC);
- }
- }
- /* }}} */
- /* {{{ proto public string|false ReflectionClass::getExtensionName()
- Returns false or the name of the extension the class belongs to */
- ZEND_METHOD(reflection_class, getExtensionName)
- {
- reflection_object *intern;
- zend_class_entry *ce;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- METHOD_NOTSTATIC(reflection_class_ptr);
- GET_REFLECTION_OBJECT_PTR(ce);
- if ((ce->type == ZEND_INTERNAL_CLASS) && ce->info.internal.module) {
- RETURN_STRING(ce->info.internal.module->name, 1);
- } else {
- RETURN_FALSE;
- }
- }
- /* }}} */
- /* {{{ proto public bool ReflectionClass::inNamespace()
- Returns whether this class is defined in namespace */
- ZEND_METHOD(reflection_class, inNamespace)
- {
- zval **name;
- const char *backslash;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- if (zend_hash_find(Z_OBJPROP_P(getThis()), "name", sizeof("name"), (void **) &name) == FAILURE) {
- RETURN_FALSE;
- }
- if (Z_TYPE_PP(name) == IS_STRING
- && (backslash = zend_memrchr(Z_STRVAL_PP(name), '\\', Z_STRLEN_PP(name)))
- && backslash > Z_STRVAL_PP(name))
- {
- RETURN_TRUE;
- }
- RETURN_FALSE;
- }
- /* }}} */
- /* {{{ proto public string ReflectionClass::getNamespaceName()
- Returns the name of namespace where this class is defined */
- ZEND_METHOD(reflection_class, getNamespaceName)
- {
- zval **name;
- const char *backslash;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- if (zend_hash_find(Z_OBJPROP_P(getThis()), "name", sizeof("name"), (void **) &name) == FAILURE) {
- RETURN_FALSE;
- }
- if (Z_TYPE_PP(name) == IS_STRING
- && (backslash = zend_memrchr(Z_STRVAL_PP(name), '\\', Z_STRLEN_PP(name)))
- && backslash > Z_STRVAL_PP(name))
- {
- RETURN_STRINGL(Z_STRVAL_PP(name), backslash - Z_STRVAL_PP(name), 1);
- }
- RETURN_EMPTY_STRING();
- }
- /* }}} */
- /* {{{ proto public string ReflectionClass::getShortName()
- Returns the short name of the class (without namespace part) */
- ZEND_METHOD(reflection_class, getShortName)
- {
- zval **name;
- const char *backslash;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- if (zend_hash_find(Z_OBJPROP_P(getThis()), "name", sizeof("name"), (void **) &name) == FAILURE) {
- RETURN_FALSE;
- }
- if (Z_TYPE_PP(name) == IS_STRING
- && (backslash = zend_memrchr(Z_STRVAL_PP(name), '\\', Z_STRLEN_PP(name)))
- && backslash > Z_STRVAL_PP(name))
- {
- RETURN_STRINGL(backslash + 1, Z_STRLEN_PP(name) - (backslash - Z_STRVAL_PP(name) + 1), 1);
- }
- RETURN_ZVAL(*name, 1, 0);
- }
- /* }}} */
- /* {{{ proto public static mixed ReflectionObject::export(mixed argument [, bool return]) throws ReflectionException
- Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */
- ZEND_METHOD(reflection_object, export)
- {
- _reflection_export(INTERNAL_FUNCTION_PARAM_PASSTHRU, reflection_object_ptr, 1);
- }
- /* }}} */
- /* {{{ proto public void ReflectionObject::__construct(mixed argument) throws ReflectionException
- Constructor. Takes an instance as an argument */
- ZEND_METHOD(reflection_object, __construct)
- {
- reflection_class_object_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
- }
- /* }}} */
- /* {{{ proto public static mixed ReflectionProperty::export(mixed class, string name [, bool return]) throws ReflectionException
- Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */
- ZEND_METHOD(reflection_property, export)
- {
- _reflection_export(INTERNAL_FUNCTION_PARAM_PASSTHRU, reflection_property_ptr, 2);
- }
- /* }}} */
- /* {{{ proto public void ReflectionProperty::__construct(mixed class, string name)
- Constructor. Throws an Exception in case the given property does not exist */
- ZEND_METHOD(reflection_property, __construct)
- {
- zval *propname, *classname;
- char *name_str;
- const char *class_name, *prop_name;
- int name_len, dynam_prop = 0;
- zval *object;
- reflection_object *intern;
- zend_class_entry **pce;
- zend_class_entry *ce;
- zend_property_info *property_info = NULL;
- property_reference *reference;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &classname, &name_str, &name_len) == FAILURE) {
- return;
- }
- object = getThis();
- intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC);
- if (intern == NULL) {
- return;
- }
- /* Find the class entry */
- switch (Z_TYPE_P(classname)) {
- case IS_STRING:
- if (zend_lookup_class(Z_STRVAL_P(classname), Z_STRLEN_P(classname), &pce TSRMLS_CC) == FAILURE) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Class %s does not exist", Z_STRVAL_P(classname));
- return;
- }
- ce = *pce;
- break;
- case IS_OBJECT:
- ce = Z_OBJCE_P(classname);
- break;
- default:
- _DO_THROW("The parameter class is expected to be either a string or an object");
- /* returns out of this function */
- }
- if (zend_hash_find(&ce->properties_info, name_str, name_len + 1, (void **) &property_info) == FAILURE || (property_info->flags & ZEND_ACC_SHADOW)) {
- /* Check for dynamic properties */
- if (property_info == NULL && Z_TYPE_P(classname) == IS_OBJECT && Z_OBJ_HT_P(classname)->get_properties) {
- if (zend_hash_exists(Z_OBJ_HT_P(classname)->get_properties(classname TSRMLS_CC), name_str, name_len+1)) {
- dynam_prop = 1;
- }
- }
- if (dynam_prop == 0) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Property %s::$%s does not exist", ce->name, name_str);
- return;
- }
- }
- if (dynam_prop == 0 && (property_info->flags & ZEND_ACC_PRIVATE) == 0) {
- /* we have to search the class hierarchy for this (implicit) public or protected property */
- zend_class_entry *tmp_ce = ce;
- zend_property_info *tmp_info;
- while (tmp_ce && zend_hash_find(&tmp_ce->properties_info, name_str, name_len + 1, (void **) &tmp_info) != SUCCESS) {
- ce = tmp_ce;
- property_info = tmp_info;
- tmp_ce = tmp_ce->parent;
- }
- }
- MAKE_STD_ZVAL(classname);
- MAKE_STD_ZVAL(propname);
- if (dynam_prop == 0) {
- zend_unmangle_property_name(property_info->name, property_info->name_length, &class_name, &prop_name);
- ZVAL_STRINGL(classname, property_info->ce->name, property_info->ce->name_length, 1);
- ZVAL_STRING(propname, prop_name, 1);
- } else {
- ZVAL_STRINGL(classname, ce->name, ce->name_length, 1);
- ZVAL_STRINGL(propname, name_str, name_len, 1);
- }
- reflection_update_property(object, "class", classname);
- reflection_update_property(object, "name", propname);
- reference = (property_reference*) emalloc(sizeof(property_reference));
- if (dynam_prop) {
- reference->prop.flags = ZEND_ACC_IMPLICIT_PUBLIC;
- reference->prop.name = Z_STRVAL_P(propname);
- reference->prop.name_length = Z_STRLEN_P(propname);
- reference->prop.h = zend_get_hash_value(name_str, name_len+1);
- reference->prop.doc_comment = NULL;
- reference->prop.ce = ce;
- } else {
- reference->prop = *property_info;
- }
- reference->ce = ce;
- intern->ptr = reference;
- intern->ref_type = REF_TYPE_PROPERTY;
- intern->ce = ce;
- intern->ignore_visibility = 0;
- }
- /* }}} */
- /* {{{ proto public string ReflectionProperty::__toString()
- Returns a string representation */
- ZEND_METHOD(reflection_property, __toString)
- {
- reflection_object *intern;
- property_reference *ref;
- string str;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ref);
- string_init(&str);
- _property_string(&str, &ref->prop, NULL, "" TSRMLS_CC);
- RETURN_STRINGL(str.string, str.len - 1, 0);
- }
- /* }}} */
- /* {{{ proto public string ReflectionProperty::getName()
- Returns the class' name */
- ZEND_METHOD(reflection_property, getName)
- {
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- _default_get_entry(getThis(), "name", sizeof("name"), return_value TSRMLS_CC);
- }
- /* }}} */
- static void _property_check_flag(INTERNAL_FUNCTION_PARAMETERS, int mask) /* {{{ */
- {
- reflection_object *intern;
- property_reference *ref;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ref);
- RETURN_BOOL(ref->prop.flags & mask);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionProperty::isPublic()
- Returns whether this property is public */
- ZEND_METHOD(reflection_property, isPublic)
- {
- _property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PUBLIC | ZEND_ACC_IMPLICIT_PUBLIC);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionProperty::isPrivate()
- Returns whether this property is private */
- ZEND_METHOD(reflection_property, isPrivate)
- {
- _property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PRIVATE);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionProperty::isProtected()
- Returns whether this property is protected */
- ZEND_METHOD(reflection_property, isProtected)
- {
- _property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PROTECTED);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionProperty::isStatic()
- Returns whether this property is static */
- ZEND_METHOD(reflection_property, isStatic)
- {
- _property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_STATIC);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionProperty::isDefault()
- Returns whether this property is default (declared at compilation time). */
- ZEND_METHOD(reflection_property, isDefault)
- {
- _property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ~ZEND_ACC_IMPLICIT_PUBLIC);
- }
- /* }}} */
- /* {{{ proto public int ReflectionProperty::getModifiers()
- Returns a bitfield of the access modifiers for this property */
- ZEND_METHOD(reflection_property, getModifiers)
- {
- reflection_object *intern;
- property_reference *ref;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ref);
- RETURN_LONG(ref->prop.flags);
- }
- /* }}} */
- /* {{{ proto public mixed ReflectionProperty::getValue([stdclass object])
- Returns this property's value */
- ZEND_METHOD(reflection_property, getValue)
- {
- reflection_object *intern;
- property_reference *ref;
- zval *object, name;
- zval *member_p = NULL;
- METHOD_NOTSTATIC(reflection_property_ptr);
- GET_REFLECTION_OBJECT_PTR(ref);
- if (!(ref->prop.flags & (ZEND_ACC_PUBLIC | ZEND_ACC_IMPLICIT_PUBLIC)) && intern->ignore_visibility == 0) {
- _default_get_entry(getThis(), "name", sizeof("name"), &name TSRMLS_CC);
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Cannot access non-public member %s::%s", intern->ce->name, Z_STRVAL(name));
- zval_dtor(&name);
- return;
- }
- if ((ref->prop.flags & ZEND_ACC_STATIC)) {
- zend_update_class_constants(intern->ce TSRMLS_CC);
- if (!CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Could not find the property %s::%s", intern->ce->name, ref->prop.name);
- /* Bails out */
- }
- *return_value= *CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset];
- zval_copy_ctor(return_value);
- INIT_PZVAL(return_value);
- } else {
- const char *class_name, *prop_name;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &object) == FAILURE) {
- return;
- }
- zend_unmangle_property_name(ref->prop.name, ref->prop.name_length, &class_name, &prop_name);
- member_p = zend_read_property(ref->ce, object, prop_name, strlen(prop_name), 1 TSRMLS_CC);
- MAKE_COPY_ZVAL(&member_p, return_value);
- if (member_p != EG(uninitialized_zval_ptr)) {
- zval_add_ref(&member_p);
- zval_ptr_dtor(&member_p);
- }
- }
- }
- /* }}} */
- /* {{{ proto public void ReflectionProperty::setValue([stdclass object,] mixed value)
- Sets this property's value */
- ZEND_METHOD(reflection_property, setValue)
- {
- reflection_object *intern;
- property_reference *ref;
- zval **variable_ptr;
- zval *object, name;
- zval *value;
- zval *tmp;
- METHOD_NOTSTATIC(reflection_property_ptr);
- GET_REFLECTION_OBJECT_PTR(ref);
- if (!(ref->prop.flags & ZEND_ACC_PUBLIC) && intern->ignore_visibility == 0) {
- _default_get_entry(getThis(), "name", sizeof("name"), &name TSRMLS_CC);
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Cannot access non-public member %s::%s", intern->ce->name, Z_STRVAL(name));
- zval_dtor(&name);
- return;
- }
- if ((ref->prop.flags & ZEND_ACC_STATIC)) {
- if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "z", &value) == FAILURE) {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &tmp, &value) == FAILURE) {
- return;
- }
- }
- zend_update_class_constants(intern->ce TSRMLS_CC);
- if (!CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Could not find the property %s::%s", intern->ce->name, ref->prop.name);
- /* Bails out */
- }
- variable_ptr = &CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset];
- if (*variable_ptr != value) {
- if (PZVAL_IS_REF(*variable_ptr)) {
- zval garbage = **variable_ptr; /* old value should be destroyed */
- /* To check: can't *variable_ptr be some system variable like error_zval here? */
- Z_TYPE_PP(variable_ptr) = Z_TYPE_P(value);
- (*variable_ptr)->value = value->value;
- if (Z_REFCOUNT_P(value) > 0) {
- zval_copy_ctor(*variable_ptr);
- }
- zval_dtor(&garbage);
- } else {
- zval *garbage = *variable_ptr;
- /* if we assign referenced variable, we should separate it */
- Z_ADDREF_P(value);
- if (PZVAL_IS_REF(value)) {
- SEPARATE_ZVAL(&value);
- }
- *variable_ptr = value;
- zval_ptr_dtor(&garbage);
- }
- }
- } else {
- const char *class_name, *prop_name;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "oz", &object, &value) == FAILURE) {
- return;
- }
- zend_unmangle_property_name(ref->prop.name, ref->prop.name_length, &class_name, &prop_name);
- zend_update_property(ref->ce, object, prop_name, strlen(prop_name), value TSRMLS_CC);
- }
- }
- /* }}} */
- /* {{{ proto public ReflectionClass ReflectionProperty::getDeclaringClass()
- Get the declaring class */
- ZEND_METHOD(reflection_property, getDeclaringClass)
- {
- reflection_object *intern;
- property_reference *ref;
- zend_class_entry *tmp_ce, *ce;
- zend_property_info *tmp_info;
- const char *prop_name, *class_name;
- int prop_name_len;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ref);
- if (zend_unmangle_property_name(ref->prop.name, ref->prop.name_length, &class_name, &prop_name) != SUCCESS) {
- RETURN_FALSE;
- }
- prop_name_len = strlen(prop_name);
- ce = tmp_ce = ref->ce;
- while (tmp_ce && zend_hash_find(&tmp_ce->properties_info, prop_name, prop_name_len + 1, (void **) &tmp_info) == SUCCESS) {
- if (tmp_info->flags & ZEND_ACC_PRIVATE || tmp_info->flags & ZEND_ACC_SHADOW) {
- /* it's a private property, so it can't be inherited */
- break;
- }
- ce = tmp_ce;
- if (tmp_ce == tmp_info->ce) {
- /* declared in this class, done */
- break;
- }
- tmp_ce = tmp_ce->parent;
- }
- zend_reflection_class_factory(ce, return_value TSRMLS_CC);
- }
- /* }}} */
- /* {{{ proto public string ReflectionProperty::getDocComment()
- Returns the doc comment for this property */
- ZEND_METHOD(reflection_property, getDocComment)
- {
- reflection_object *intern;
- property_reference *ref;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(ref);
- if (ref->prop.doc_comment) {
- RETURN_STRINGL(ref->prop.doc_comment, ref->prop.doc_comment_len, 1);
- }
- RETURN_FALSE;
- }
- /* }}} */
- /* {{{ proto public int ReflectionProperty::setAccessible(bool visible)
- Sets whether non-public properties can be requested */
- ZEND_METHOD(reflection_property, setAccessible)
- {
- reflection_object *intern;
- zend_bool visible;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &visible) == FAILURE) {
- return;
- }
- intern = (reflection_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
- if (intern == NULL) {
- return;
- }
- intern->ignore_visibility = visible;
- }
- /* }}} */
- /* {{{ proto public static mixed ReflectionExtension::export(string name [, bool return]) throws ReflectionException
- Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */
- ZEND_METHOD(reflection_extension, export)
- {
- _reflection_export(INTERNAL_FUNCTION_PARAM_PASSTHRU, reflection_extension_ptr, 1);
- }
- /* }}} */
- /* {{{ proto public void ReflectionExtension::__construct(string name)
- Constructor. Throws an Exception in case the given extension does not exist */
- ZEND_METHOD(reflection_extension, __construct)
- {
- zval *name;
- zval *object;
- char *lcname;
- reflection_object *intern;
- zend_module_entry *module;
- char *name_str;
- int name_len;
- ALLOCA_FLAG(use_heap)
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len) == FAILURE) {
- return;
- }
- object = getThis();
- intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC);
- if (intern == NULL) {
- return;
- }
- lcname = do_alloca(name_len + 1, use_heap);
- zend_str_tolower_copy(lcname, name_str, name_len);
- if (zend_hash_find(&module_registry, lcname, name_len + 1, (void **)&module) == FAILURE) {
- free_alloca(lcname, use_heap);
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Extension %s does not exist", name_str);
- return;
- }
- free_alloca(lcname, use_heap);
- MAKE_STD_ZVAL(name);
- ZVAL_STRING(name, module->name, 1);
- reflection_update_property( object, "name", name);
- intern->ptr = module;
- intern->ref_type = REF_TYPE_OTHER;
- intern->ce = NULL;
- }
- /* }}} */
- /* {{{ proto public string ReflectionExtension::__toString()
- Returns a string representation */
- ZEND_METHOD(reflection_extension, __toString)
- {
- reflection_object *intern;
- zend_module_entry *module;
- string str;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(module);
- string_init(&str);
- _extension_string(&str, module, "" TSRMLS_CC);
- RETURN_STRINGL(str.string, str.len - 1, 0);
- }
- /* }}} */
- /* {{{ proto public string ReflectionExtension::getName()
- Returns this extension's name */
- ZEND_METHOD(reflection_extension, getName)
- {
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- _default_get_entry(getThis(), "name", sizeof("name"), return_value TSRMLS_CC);
- }
- /* }}} */
- /* {{{ proto public string ReflectionExtension::getVersion()
- Returns this extension's version */
- ZEND_METHOD(reflection_extension, getVersion)
- {
- reflection_object *intern;
- zend_module_entry *module;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(module);
- /* An extension does not necessarily have a version number */
- if (module->version == NO_VERSION_YET) {
- RETURN_NULL();
- } else {
- RETURN_STRING(module->version, 1);
- }
- }
- /* }}} */
- /* {{{ proto public ReflectionFunction[] ReflectionExtension::getFunctions()
- Returns an array of this extension's functions */
- ZEND_METHOD(reflection_extension, getFunctions)
- {
- reflection_object *intern;
- zend_module_entry *module;
- HashPosition iterator;
- zval *function;
- zend_function *fptr;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(module);
- array_init(return_value);
- zend_hash_internal_pointer_reset_ex(CG(function_table), &iterator);
- while (zend_hash_get_current_data_ex(CG(function_table), (void **) &fptr, &iterator) == SUCCESS) {
- if (fptr->common.type==ZEND_INTERNAL_FUNCTION
- && fptr->internal_function.module == module) {
- ALLOC_ZVAL(function);
- reflection_function_factory(fptr, NULL, function TSRMLS_CC);
- add_assoc_zval(return_value, fptr->common.function_name, function);
- }
- zend_hash_move_forward_ex(CG(function_table), &iterator);
- }
- }
- /* }}} */
- static int _addconstant(zend_constant *constant TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
- {
- zval *const_val;
- zval *retval = va_arg(args, zval*);
- int number = va_arg(args, int);
- if (number == constant->module_number) {
- ALLOC_ZVAL(const_val);
- *const_val = constant->value;
- zval_copy_ctor(const_val);
- INIT_PZVAL(const_val);
- add_assoc_zval_ex(retval, constant->name, constant->name_len, const_val);
- }
- return 0;
- }
- /* }}} */
- /* {{{ proto public array ReflectionExtension::getConstants()
- Returns an associative array containing this extension's constants and their values */
- ZEND_METHOD(reflection_extension, getConstants)
- {
- reflection_object *intern;
- zend_module_entry *module;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(module);
- array_init(return_value);
- zend_hash_apply_with_arguments(EG(zend_constants) TSRMLS_CC, (apply_func_args_t) _addconstant, 2, return_value, module->module_number);
- }
- /* }}} */
- /* {{{ _addinientry */
- static int _addinientry(zend_ini_entry *ini_entry TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
- {
- zval *retval = va_arg(args, zval*);
- int number = va_arg(args, int);
- if (number == ini_entry->module_number) {
- if (ini_entry->value) {
- add_assoc_stringl(retval, ini_entry->name, ini_entry->value, ini_entry->value_length, 1);
- } else {
- add_assoc_null(retval, ini_entry->name);
- }
- }
- return ZEND_HASH_APPLY_KEEP;
- }
- /* }}} */
- /* {{{ proto public array ReflectionExtension::getINIEntries()
- Returns an associative array containing this extension's INI entries and their values */
- ZEND_METHOD(reflection_extension, getINIEntries)
- {
- reflection_object *intern;
- zend_module_entry *module;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(module);
- array_init(return_value);
- zend_hash_apply_with_arguments(EG(ini_directives) TSRMLS_CC, (apply_func_args_t) _addinientry, 2, return_value, module->module_number);
- }
- /* }}} */
- /* {{{ add_extension_class */
- static int add_extension_class(zend_class_entry **pce TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
- {
- zval *class_array = va_arg(args, zval*), *zclass;
- struct _zend_module_entry *module = va_arg(args, struct _zend_module_entry*);
- int add_reflection_class = va_arg(args, int);
- if (((*pce)->type == ZEND_INTERNAL_CLASS) && (*pce)->info.internal.module && !strcasecmp((*pce)->info.internal.module->name, module->name)) {
- const char *name;
- int nlen;
- if (zend_binary_strcasecmp((*pce)->name, (*pce)->name_length, hash_key->arKey, hash_key->nKeyLength-1)) {
- /* This is an class alias, use alias name */
- name = hash_key->arKey;
- nlen = hash_key->nKeyLength-1;
- } else {
- /* Use class name */
- name = (*pce)->name;
- nlen = (*pce)->name_length;
- }
- if (add_reflection_class) {
- ALLOC_ZVAL(zclass);
- zend_reflection_class_factory(*pce, zclass TSRMLS_CC);
- add_assoc_zval_ex(class_array, name, nlen+1, zclass);
- } else {
- add_next_index_stringl(class_array, name, nlen, 1);
- }
- }
- return ZEND_HASH_APPLY_KEEP;
- }
- /* }}} */
- /* {{{ proto public ReflectionClass[] ReflectionExtension::getClasses()
- Returns an array containing ReflectionClass objects for all classes of this extension */
- ZEND_METHOD(reflection_extension, getClasses)
- {
- reflection_object *intern;
- zend_module_entry *module;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(module);
- array_init(return_value);
- zend_hash_apply_with_arguments(EG(class_table) TSRMLS_CC, (apply_func_args_t) add_extension_class, 3, return_value, module, 1);
- }
- /* }}} */
- /* {{{ proto public array ReflectionExtension::getClassNames()
- Returns an array containing all names of all classes of this extension */
- ZEND_METHOD(reflection_extension, getClassNames)
- {
- reflection_object *intern;
- zend_module_entry *module;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(module);
- array_init(return_value);
- zend_hash_apply_with_arguments(EG(class_table) TSRMLS_CC, (apply_func_args_t) add_extension_class, 3, return_value, module, 0);
- }
- /* }}} */
- /* {{{ proto public array ReflectionExtension::getDependencies()
- Returns an array containing all names of all extensions this extension depends on */
- ZEND_METHOD(reflection_extension, getDependencies)
- {
- reflection_object *intern;
- zend_module_entry *module;
- const zend_module_dep *dep;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(module);
- array_init(return_value);
- dep = module->deps;
- if (!dep)
- {
- return;
- }
- while(dep->name) {
- char *relation;
- char *rel_type;
- int len;
- switch(dep->type) {
- case MODULE_DEP_REQUIRED:
- rel_type = "Required";
- break;
- case MODULE_DEP_CONFLICTS:
- rel_type = "Conflicts";
- break;
- case MODULE_DEP_OPTIONAL:
- rel_type = "Optional";
- break;
- default:
- rel_type = "Error"; /* shouldn't happen */
- break;
- }
- len = spprintf(&relation, 0, "%s%s%s%s%s",
- rel_type,
- dep->rel ? " " : "",
- dep->rel ? dep->rel : "",
- dep->version ? " " : "",
- dep->version ? dep->version : "");
- add_assoc_stringl(return_value, dep->name, relation, len, 0);
- dep++;
- }
- }
- /* }}} */
- /* {{{ proto public void ReflectionExtension::info()
- Prints phpinfo block for the extension */
- ZEND_METHOD(reflection_extension, info)
- {
- reflection_object *intern;
- zend_module_entry *module;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(module);
- php_info_print_module(module TSRMLS_CC);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionExtension::isPersistent()
- Returns whether this extension is persistent */
- ZEND_METHOD(reflection_extension, isPersistent)
- {
- reflection_object *intern;
- zend_module_entry *module;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(module);
- RETURN_BOOL(module->type == MODULE_PERSISTENT);
- }
- /* }}} */
- /* {{{ proto public bool ReflectionExtension::isTemporary()
- Returns whether this extension is temporary */
- ZEND_METHOD(reflection_extension, isTemporary)
- {
- reflection_object *intern;
- zend_module_entry *module;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(module);
- RETURN_BOOL(module->type == MODULE_TEMPORARY);
- }
- /* }}} */
- /* {{{ proto public static mixed ReflectionZendExtension::export(string name [, bool return]) throws ReflectionException
- * Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */
- ZEND_METHOD(reflection_zend_extension, export)
- {
- _reflection_export(INTERNAL_FUNCTION_PARAM_PASSTHRU, reflection_zend_extension_ptr, 1);
- }
- /* }}} */
- /* {{{ proto public void ReflectionZendExtension::__construct(string name)
- Constructor. Throws an Exception in case the given Zend extension does not exist */
- ZEND_METHOD(reflection_zend_extension, __construct)
- {
- zval *name;
- zval *object;
- reflection_object *intern;
- zend_extension *extension;
- char *name_str;
- int name_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len) == FAILURE) {
- return;
- }
- object = getThis();
- intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC);
- if (intern == NULL) {
- return;
- }
- extension = zend_get_extension(name_str);
- if (!extension) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Zend Extension %s does not exist", name_str);
- return;
- }
- MAKE_STD_ZVAL(name);
- ZVAL_STRING(name, extension->name, 1);
- reflection_update_property(object, "name", name);
- intern->ptr = extension;
- intern->ref_type = REF_TYPE_OTHER;
- intern->ce = NULL;
- }
- /* }}} */
- /* {{{ proto public string ReflectionZendExtension::__toString()
- Returns a string representation */
- ZEND_METHOD(reflection_zend_extension, __toString)
- {
- reflection_object *intern;
- zend_extension *extension;
- string str;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(extension);
- string_init(&str);
- _zend_extension_string(&str, extension, "" TSRMLS_CC);
- RETURN_STRINGL(str.string, str.len - 1, 0);
- }
- /* }}} */
- /* {{{ proto public string ReflectionZendExtension::getName()
- Returns the name of this Zend extension */
- ZEND_METHOD(reflection_zend_extension, getName)
- {
- reflection_object *intern;
- zend_extension *extension;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(extension);
- RETURN_STRING(extension->name, 1);
- }
- /* }}} */
- /* {{{ proto public string ReflectionZendExtension::getVersion()
- Returns the version information of this Zend extension */
- ZEND_METHOD(reflection_zend_extension, getVersion)
- {
- reflection_object *intern;
- zend_extension *extension;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(extension);
- RETURN_STRING(extension->version ? extension->version : "", 1);
- }
- /* }}} */
- /* {{{ proto public void ReflectionZendExtension::getAuthor()
- * Returns the name of this Zend extension's author */
- ZEND_METHOD(reflection_zend_extension, getAuthor)
- {
- reflection_object *intern;
- zend_extension *extension;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(extension);
- RETURN_STRING(extension->author ? extension->author : "", 1);
- }
- /* }}} */
- /* {{{ proto public void ReflectionZendExtension::getURL()
- Returns this Zend extension's URL*/
- ZEND_METHOD(reflection_zend_extension, getURL)
- {
- reflection_object *intern;
- zend_extension *extension;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(extension);
- RETURN_STRING(extension->URL ? extension->URL : "", 1);
- }
- /* }}} */
- /* {{{ proto public void ReflectionZendExtension::getCopyright()
- Returns this Zend extension's copyright information */
- ZEND_METHOD(reflection_zend_extension, getCopyright)
- {
- reflection_object *intern;
- zend_extension *extension;
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- GET_REFLECTION_OBJECT_PTR(extension);
- RETURN_STRING(extension->copyright ? extension->copyright : "", 1);
- }
- /* }}} */
- /* {{{ method tables */
- static const zend_function_entry reflection_exception_functions[] = {
- PHP_FE_END
- };
- ZEND_BEGIN_ARG_INFO(arginfo_reflection__void, 0)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_getModifierNames, 0)
- ZEND_ARG_INFO(0, modifiers)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_export, 0, 0, 1)
- ZEND_ARG_OBJ_INFO(0, reflector, Reflector, 0)
- ZEND_ARG_INFO(0, return)
- ZEND_END_ARG_INFO()
- static const zend_function_entry reflection_functions[] = {
- ZEND_ME(reflection, getModifierNames, arginfo_reflection_getModifierNames, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
- ZEND_ME(reflection, export, arginfo_reflection_export, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
- PHP_FE_END
- };
- static const zend_function_entry reflector_functions[] = {
- ZEND_FENTRY(export, NULL, NULL, ZEND_ACC_STATIC|ZEND_ACC_ABSTRACT|ZEND_ACC_PUBLIC)
- ZEND_ABSTRACT_ME(reflector, __toString, arginfo_reflection__void)
- PHP_FE_END
- };
- ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_function_export, 0, 0, 1)
- ZEND_ARG_INFO(0, name)
- ZEND_ARG_INFO(0, return)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_function___construct, 0)
- ZEND_ARG_INFO(0, name)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_function_invoke, 0, 0, 0)
- ZEND_ARG_INFO(0, args)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_function_invokeArgs, 0)
- ZEND_ARG_ARRAY_INFO(0, args, 0)
- ZEND_END_ARG_INFO()
- static const zend_function_entry reflection_function_abstract_functions[] = {
- ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
- PHP_ABSTRACT_ME(reflection_function, __toString, arginfo_reflection__void)
- ZEND_ME(reflection_function, inNamespace, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, isClosure, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, isDeprecated, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, isInternal, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, isUserDefined, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, isGenerator, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, isVariadic, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, getClosureThis, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, getClosureScopeClass, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, getDocComment, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, getEndLine, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, getExtension, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, getExtensionName, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, getFileName, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, getName, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, getNamespaceName, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, getNumberOfParameters, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, getNumberOfRequiredParameters, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, getParameters, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, getShortName, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, getStartLine, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, getStaticVariables, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, returnsReference, arginfo_reflection__void, 0)
- PHP_FE_END
- };
- static const zend_function_entry reflection_function_functions[] = {
- ZEND_ME(reflection_function, __construct, arginfo_reflection_function___construct, 0)
- ZEND_ME(reflection_function, __toString, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, export, arginfo_reflection_function_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
- ZEND_ME(reflection_function, isDisabled, arginfo_reflection__void, 0)
- ZEND_ME(reflection_function, invoke, arginfo_reflection_function_invoke, 0)
- ZEND_ME(reflection_function, invokeArgs, arginfo_reflection_function_invokeArgs, 0)
- ZEND_ME(reflection_function, getClosure, arginfo_reflection__void, 0)
- PHP_FE_END
- };
- ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_method_export, 0, 0, 2)
- ZEND_ARG_INFO(0, class)
- ZEND_ARG_INFO(0, name)
- ZEND_ARG_INFO(0, return)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_method___construct, 0, 0, 1)
- ZEND_ARG_INFO(0, class_or_method)
- ZEND_ARG_INFO(0, name)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_method_invoke, 0)
- ZEND_ARG_INFO(0, object)
- ZEND_ARG_INFO(0, args)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_method_invokeArgs, 0)
- ZEND_ARG_INFO(0, object)
- ZEND_ARG_ARRAY_INFO(0, args, 0)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_method_setAccessible, 0)
- ZEND_ARG_INFO(0, value)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_method_getClosure, 0)
- ZEND_ARG_INFO(0, object)
- ZEND_END_ARG_INFO()
- static const zend_function_entry reflection_method_functions[] = {
- ZEND_ME(reflection_method, export, arginfo_reflection_method_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
- ZEND_ME(reflection_method, __construct, arginfo_reflection_method___construct, 0)
- ZEND_ME(reflection_method, __toString, arginfo_reflection__void, 0)
- ZEND_ME(reflection_method, isPublic, arginfo_reflection__void, 0)
- ZEND_ME(reflection_method, isPrivate, arginfo_reflection__void, 0)
- ZEND_ME(reflection_method, isProtected, arginfo_reflection__void, 0)
- ZEND_ME(reflection_method, isAbstract, arginfo_reflection__void, 0)
- ZEND_ME(reflection_method, isFinal, arginfo_reflection__void, 0)
- ZEND_ME(reflection_method, isStatic, arginfo_reflection__void, 0)
- ZEND_ME(reflection_method, isConstructor, arginfo_reflection__void, 0)
- ZEND_ME(reflection_method, isDestructor, arginfo_reflection__void, 0)
- ZEND_ME(reflection_method, getClosure, arginfo_reflection_method_getClosure, 0)
- ZEND_ME(reflection_method, getModifiers, arginfo_reflection__void, 0)
- ZEND_ME(reflection_method, invoke, arginfo_reflection_method_invoke, 0)
- ZEND_ME(reflection_method, invokeArgs, arginfo_reflection_method_invokeArgs, 0)
- ZEND_ME(reflection_method, getDeclaringClass, arginfo_reflection__void, 0)
- ZEND_ME(reflection_method, getPrototype, arginfo_reflection__void, 0)
- ZEND_ME(reflection_property, setAccessible, arginfo_reflection_method_setAccessible, 0)
- PHP_FE_END
- };
- ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_class_export, 0, 0, 1)
- ZEND_ARG_INFO(0, argument)
- ZEND_ARG_INFO(0, return)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_class___construct, 0)
- ZEND_ARG_INFO(0, argument)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_class_getStaticPropertyValue, 0, 0, 1)
- ZEND_ARG_INFO(0, name)
- ZEND_ARG_INFO(0, default)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_setStaticPropertyValue, 0)
- ZEND_ARG_INFO(0, name)
- ZEND_ARG_INFO(0, value)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_hasMethod, 0)
- ZEND_ARG_INFO(0, name)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_getMethod, 0)
- ZEND_ARG_INFO(0, name)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_class_getMethods, 0, 0, 0)
- ZEND_ARG_INFO(0, filter)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_hasProperty, 0)
- ZEND_ARG_INFO(0, name)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_getProperty, 0)
- ZEND_ARG_INFO(0, name)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_class_getProperties, 0, 0, 0)
- ZEND_ARG_INFO(0, filter)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_hasConstant, 0)
- ZEND_ARG_INFO(0, name)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_getConstant, 0)
- ZEND_ARG_INFO(0, name)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_isInstance, 0)
- ZEND_ARG_INFO(0, object)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_newInstance, 0)
- ZEND_ARG_INFO(0, args)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_newInstanceWithoutConstructor, 0)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_class_newInstanceArgs, 0, 0, 0)
- ZEND_ARG_ARRAY_INFO(0, args, 0)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_isSubclassOf, 0)
- ZEND_ARG_INFO(0, class)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_implementsInterface, 0)
- ZEND_ARG_INFO(0, interface)
- ZEND_END_ARG_INFO()
- static const zend_function_entry reflection_class_functions[] = {
- ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
- ZEND_ME(reflection_class, export, arginfo_reflection_class_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
- ZEND_ME(reflection_class, __construct, arginfo_reflection_class___construct, 0)
- ZEND_ME(reflection_class, __toString, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, getName, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, isInternal, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, isUserDefined, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, isInstantiable, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, isCloneable, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, getFileName, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, getStartLine, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, getEndLine, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, getDocComment, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, getConstructor, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, hasMethod, arginfo_reflection_class_hasMethod, 0)
- ZEND_ME(reflection_class, getMethod, arginfo_reflection_class_getMethod, 0)
- ZEND_ME(reflection_class, getMethods, arginfo_reflection_class_getMethods, 0)
- ZEND_ME(reflection_class, hasProperty, arginfo_reflection_class_hasProperty, 0)
- ZEND_ME(reflection_class, getProperty, arginfo_reflection_class_getProperty, 0)
- ZEND_ME(reflection_class, getProperties, arginfo_reflection_class_getProperties, 0)
- ZEND_ME(reflection_class, hasConstant, arginfo_reflection_class_hasConstant, 0)
- ZEND_ME(reflection_class, getConstants, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, getConstant, arginfo_reflection_class_getConstant, 0)
- ZEND_ME(reflection_class, getInterfaces, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, getInterfaceNames, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, isInterface, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, getTraits, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, getTraitNames, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, getTraitAliases, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, isTrait, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, isAbstract, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, isFinal, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, getModifiers, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, isInstance, arginfo_reflection_class_isInstance, 0)
- ZEND_ME(reflection_class, newInstance, arginfo_reflection_class_newInstance, 0)
- ZEND_ME(reflection_class, newInstanceWithoutConstructor, arginfo_reflection_class_newInstanceWithoutConstructor, 0)
- ZEND_ME(reflection_class, newInstanceArgs, arginfo_reflection_class_newInstanceArgs, 0)
- ZEND_ME(reflection_class, getParentClass, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, isSubclassOf, arginfo_reflection_class_isSubclassOf, 0)
- ZEND_ME(reflection_class, getStaticProperties, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, getStaticPropertyValue, arginfo_reflection_class_getStaticPropertyValue, 0)
- ZEND_ME(reflection_class, setStaticPropertyValue, arginfo_reflection_class_setStaticPropertyValue, 0)
- ZEND_ME(reflection_class, getDefaultProperties, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, isIterateable, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, implementsInterface, arginfo_reflection_class_implementsInterface, 0)
- ZEND_ME(reflection_class, getExtension, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, getExtensionName, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, inNamespace, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, getNamespaceName, arginfo_reflection__void, 0)
- ZEND_ME(reflection_class, getShortName, arginfo_reflection__void, 0)
- PHP_FE_END
- };
- ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_object_export, 0, 0, 1)
- ZEND_ARG_INFO(0, argument)
- ZEND_ARG_INFO(0, return)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_object___construct, 0)
- ZEND_ARG_INFO(0, argument)
- ZEND_END_ARG_INFO()
- static const zend_function_entry reflection_object_functions[] = {
- ZEND_ME(reflection_object, export, arginfo_reflection_object_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
- ZEND_ME(reflection_object, __construct, arginfo_reflection_object___construct, 0)
- PHP_FE_END
- };
- ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_property_export, 0, 0, 2)
- ZEND_ARG_INFO(0, class)
- ZEND_ARG_INFO(0, name)
- ZEND_ARG_INFO(0, return)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_property___construct, 0, 0, 2)
- ZEND_ARG_INFO(0, class)
- ZEND_ARG_INFO(0, name)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_property_getValue, 0, 0, 0)
- ZEND_ARG_INFO(0, object)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_property_setValue, 0, 0, 1)
- ZEND_ARG_INFO(0, object)
- ZEND_ARG_INFO(0, value)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_property_setAccessible, 0)
- ZEND_ARG_INFO(0, visible)
- ZEND_END_ARG_INFO()
- static const zend_function_entry reflection_property_functions[] = {
- ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
- ZEND_ME(reflection_property, export, arginfo_reflection_property_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
- ZEND_ME(reflection_property, __construct, arginfo_reflection_property___construct, 0)
- ZEND_ME(reflection_property, __toString, arginfo_reflection__void, 0)
- ZEND_ME(reflection_property, getName, arginfo_reflection__void, 0)
- ZEND_ME(reflection_property, getValue, arginfo_reflection_property_getValue, 0)
- ZEND_ME(reflection_property, setValue, arginfo_reflection_property_setValue, 0)
- ZEND_ME(reflection_property, isPublic, arginfo_reflection__void, 0)
- ZEND_ME(reflection_property, isPrivate, arginfo_reflection__void, 0)
- ZEND_ME(reflection_property, isProtected, arginfo_reflection__void, 0)
- ZEND_ME(reflection_property, isStatic, arginfo_reflection__void, 0)
- ZEND_ME(reflection_property, isDefault, arginfo_reflection__void, 0)
- ZEND_ME(reflection_property, getModifiers, arginfo_reflection__void, 0)
- ZEND_ME(reflection_property, getDeclaringClass, arginfo_reflection__void, 0)
- ZEND_ME(reflection_property, getDocComment, arginfo_reflection__void, 0)
- ZEND_ME(reflection_property, setAccessible, arginfo_reflection_property_setAccessible, 0)
- PHP_FE_END
- };
- ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_parameter_export, 0, 0, 2)
- ZEND_ARG_INFO(0, function)
- ZEND_ARG_INFO(0, parameter)
- ZEND_ARG_INFO(0, return)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_parameter___construct, 0)
- ZEND_ARG_INFO(0, function)
- ZEND_ARG_INFO(0, parameter)
- ZEND_END_ARG_INFO()
- static const zend_function_entry reflection_parameter_functions[] = {
- ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
- ZEND_ME(reflection_parameter, export, arginfo_reflection_parameter_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
- ZEND_ME(reflection_parameter, __construct, arginfo_reflection_parameter___construct, 0)
- ZEND_ME(reflection_parameter, __toString, arginfo_reflection__void, 0)
- ZEND_ME(reflection_parameter, getName, arginfo_reflection__void, 0)
- ZEND_ME(reflection_parameter, isPassedByReference, arginfo_reflection__void, 0)
- ZEND_ME(reflection_parameter, canBePassedByValue, arginfo_reflection__void, 0)
- ZEND_ME(reflection_parameter, getDeclaringFunction, arginfo_reflection__void, 0)
- ZEND_ME(reflection_parameter, getDeclaringClass, arginfo_reflection__void, 0)
- ZEND_ME(reflection_parameter, getClass, arginfo_reflection__void, 0)
- ZEND_ME(reflection_parameter, isArray, arginfo_reflection__void, 0)
- ZEND_ME(reflection_parameter, isCallable, arginfo_reflection__void, 0)
- ZEND_ME(reflection_parameter, allowsNull, arginfo_reflection__void, 0)
- ZEND_ME(reflection_parameter, getPosition, arginfo_reflection__void, 0)
- ZEND_ME(reflection_parameter, isOptional, arginfo_reflection__void, 0)
- ZEND_ME(reflection_parameter, isDefaultValueAvailable, arginfo_reflection__void, 0)
- ZEND_ME(reflection_parameter, getDefaultValue, arginfo_reflection__void, 0)
- ZEND_ME(reflection_parameter, isDefaultValueConstant, arginfo_reflection__void, 0)
- ZEND_ME(reflection_parameter, getDefaultValueConstantName, arginfo_reflection__void, 0)
- ZEND_ME(reflection_parameter, isVariadic, arginfo_reflection__void, 0)
- PHP_FE_END
- };
- ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_extension_export, 0, 0, 1)
- ZEND_ARG_INFO(0, name)
- ZEND_ARG_INFO(0, return)
- ZEND_END_ARG_INFO()
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_extension___construct, 0)
- ZEND_ARG_INFO(0, name)
- ZEND_END_ARG_INFO()
- static const zend_function_entry reflection_extension_functions[] = {
- ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
- ZEND_ME(reflection_extension, export, arginfo_reflection_extension_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
- ZEND_ME(reflection_extension, __construct, arginfo_reflection_extension___construct, 0)
- ZEND_ME(reflection_extension, __toString, arginfo_reflection__void, 0)
- ZEND_ME(reflection_extension, getName, arginfo_reflection__void, 0)
- ZEND_ME(reflection_extension, getVersion, arginfo_reflection__void, 0)
- ZEND_ME(reflection_extension, getFunctions, arginfo_reflection__void, 0)
- ZEND_ME(reflection_extension, getConstants, arginfo_reflection__void, 0)
- ZEND_ME(reflection_extension, getINIEntries, arginfo_reflection__void, 0)
- ZEND_ME(reflection_extension, getClasses, arginfo_reflection__void, 0)
- ZEND_ME(reflection_extension, getClassNames, arginfo_reflection__void, 0)
- ZEND_ME(reflection_extension, getDependencies, arginfo_reflection__void, 0)
- ZEND_ME(reflection_extension, info, arginfo_reflection__void, 0)
- ZEND_ME(reflection_extension, isPersistent, arginfo_reflection__void, 0)
- ZEND_ME(reflection_extension, isTemporary, arginfo_reflection__void, 0)
- PHP_FE_END
- };
- ZEND_BEGIN_ARG_INFO(arginfo_reflection_zend_extension___construct, 0)
- ZEND_ARG_INFO(0, name)
- ZEND_END_ARG_INFO()
- static const zend_function_entry reflection_zend_extension_functions[] = {
- ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
- ZEND_ME(reflection_zend_extension, export, arginfo_reflection_extension_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
- ZEND_ME(reflection_zend_extension, __construct, arginfo_reflection_zend_extension___construct, 0)
- ZEND_ME(reflection_zend_extension, __toString, arginfo_reflection__void, 0)
- ZEND_ME(reflection_zend_extension, getName, arginfo_reflection__void, 0)
- ZEND_ME(reflection_zend_extension, getVersion, arginfo_reflection__void, 0)
- ZEND_ME(reflection_zend_extension, getAuthor, arginfo_reflection__void, 0)
- ZEND_ME(reflection_zend_extension, getURL, arginfo_reflection__void, 0)
- ZEND_ME(reflection_zend_extension, getCopyright, arginfo_reflection__void, 0)
- PHP_FE_END
- };
- /* }}} */
- const zend_function_entry reflection_ext_functions[] = { /* {{{ */
- PHP_FE_END
- }; /* }}} */
- static zend_object_handlers *zend_std_obj_handlers;
- /* {{{ _reflection_write_property */
- static void _reflection_write_property(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC)
- {
- if ((Z_TYPE_P(member) == IS_STRING)
- && zend_hash_exists(&Z_OBJCE_P(object)->properties_info, Z_STRVAL_P(member), Z_STRLEN_P(member)+1)
- && ((Z_STRLEN_P(member) == sizeof("name") - 1 && !memcmp(Z_STRVAL_P(member), "name", sizeof("name")))
- || (Z_STRLEN_P(member) == sizeof("class") - 1 && !memcmp(Z_STRVAL_P(member), "class", sizeof("class")))))
- {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Cannot set read-only property %s::$%s", Z_OBJCE_P(object)->name, Z_STRVAL_P(member));
- }
- else
- {
- zend_std_obj_handlers->write_property(object, member, value, key TSRMLS_CC);
- }
- }
- /* }}} */
- PHP_MINIT_FUNCTION(reflection) /* {{{ */
- {
- zend_class_entry _reflection_entry;
- zend_std_obj_handlers = zend_get_std_object_handlers();
- memcpy(&reflection_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
- reflection_object_handlers.clone_obj = NULL;
- reflection_object_handlers.write_property = _reflection_write_property;
- INIT_CLASS_ENTRY(_reflection_entry, "ReflectionException", reflection_exception_functions);
- reflection_exception_ptr = zend_register_internal_class_ex(&_reflection_entry, zend_exception_get_default(TSRMLS_C), NULL TSRMLS_CC);
- INIT_CLASS_ENTRY(_reflection_entry, "Reflection", reflection_functions);
- reflection_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC);
- INIT_CLASS_ENTRY(_reflection_entry, "Reflector", reflector_functions);
- reflector_ptr = zend_register_internal_interface(&_reflection_entry TSRMLS_CC);
- INIT_CLASS_ENTRY(_reflection_entry, "ReflectionFunctionAbstract", reflection_function_abstract_functions);
- _reflection_entry.create_object = reflection_objects_new;
- reflection_function_abstract_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC);
- reflection_register_implement(reflection_function_abstract_ptr, reflector_ptr TSRMLS_CC);
- zend_declare_property_string(reflection_function_abstract_ptr, "name", sizeof("name")-1, "", ZEND_ACC_ABSTRACT TSRMLS_CC);
- INIT_CLASS_ENTRY(_reflection_entry, "ReflectionFunction", reflection_function_functions);
- _reflection_entry.create_object = reflection_objects_new;
- reflection_function_ptr = zend_register_internal_class_ex(&_reflection_entry, reflection_function_abstract_ptr, NULL TSRMLS_CC);
- zend_declare_property_string(reflection_function_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC);
- REGISTER_REFLECTION_CLASS_CONST_LONG(function, "IS_DEPRECATED", ZEND_ACC_DEPRECATED);
- INIT_CLASS_ENTRY(_reflection_entry, "ReflectionParameter", reflection_parameter_functions);
- _reflection_entry.create_object = reflection_objects_new;
- reflection_parameter_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC);
- reflection_register_implement(reflection_parameter_ptr, reflector_ptr TSRMLS_CC);
- zend_declare_property_string(reflection_parameter_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC);
- INIT_CLASS_ENTRY(_reflection_entry, "ReflectionMethod", reflection_method_functions);
- _reflection_entry.create_object = reflection_objects_new;
- reflection_method_ptr = zend_register_internal_class_ex(&_reflection_entry, reflection_function_abstract_ptr, NULL TSRMLS_CC);
- zend_declare_property_string(reflection_method_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC);
- zend_declare_property_string(reflection_method_ptr, "class", sizeof("class")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC);
- REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_STATIC", ZEND_ACC_STATIC);
- REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_PUBLIC", ZEND_ACC_PUBLIC);
- REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_PROTECTED", ZEND_ACC_PROTECTED);
- REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_PRIVATE", ZEND_ACC_PRIVATE);
- REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_ABSTRACT", ZEND_ACC_ABSTRACT);
- REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_FINAL", ZEND_ACC_FINAL);
- INIT_CLASS_ENTRY(_reflection_entry, "ReflectionClass", reflection_class_functions);
- _reflection_entry.create_object = reflection_objects_new;
- reflection_class_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC);
- reflection_register_implement(reflection_class_ptr, reflector_ptr TSRMLS_CC);
- zend_declare_property_string(reflection_class_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC);
- REGISTER_REFLECTION_CLASS_CONST_LONG(class, "IS_IMPLICIT_ABSTRACT", ZEND_ACC_IMPLICIT_ABSTRACT_CLASS);
- REGISTER_REFLECTION_CLASS_CONST_LONG(class, "IS_EXPLICIT_ABSTRACT", ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
- REGISTER_REFLECTION_CLASS_CONST_LONG(class, "IS_FINAL", ZEND_ACC_FINAL_CLASS);
- INIT_CLASS_ENTRY(_reflection_entry, "ReflectionObject", reflection_object_functions);
- _reflection_entry.create_object = reflection_objects_new;
- reflection_object_ptr = zend_register_internal_class_ex(&_reflection_entry, reflection_class_ptr, NULL TSRMLS_CC);
- INIT_CLASS_ENTRY(_reflection_entry, "ReflectionProperty", reflection_property_functions);
- _reflection_entry.create_object = reflection_objects_new;
- reflection_property_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC);
- reflection_register_implement(reflection_property_ptr, reflector_ptr TSRMLS_CC);
- zend_declare_property_string(reflection_property_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC);
- zend_declare_property_string(reflection_property_ptr, "class", sizeof("class")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC);
- REGISTER_REFLECTION_CLASS_CONST_LONG(property, "IS_STATIC", ZEND_ACC_STATIC);
- REGISTER_REFLECTION_CLASS_CONST_LONG(property, "IS_PUBLIC", ZEND_ACC_PUBLIC);
- REGISTER_REFLECTION_CLASS_CONST_LONG(property, "IS_PROTECTED", ZEND_ACC_PROTECTED);
- REGISTER_REFLECTION_CLASS_CONST_LONG(property, "IS_PRIVATE", ZEND_ACC_PRIVATE);
- INIT_CLASS_ENTRY(_reflection_entry, "ReflectionExtension", reflection_extension_functions);
- _reflection_entry.create_object = reflection_objects_new;
- reflection_extension_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC);
- reflection_register_implement(reflection_extension_ptr, reflector_ptr TSRMLS_CC);
- zend_declare_property_string(reflection_extension_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC);
- INIT_CLASS_ENTRY(_reflection_entry, "ReflectionZendExtension", reflection_zend_extension_functions);
- _reflection_entry.create_object = reflection_objects_new;
- reflection_zend_extension_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC);
- reflection_register_implement(reflection_zend_extension_ptr, reflector_ptr TSRMLS_CC);
- zend_declare_property_string(reflection_zend_extension_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC);
- return SUCCESS;
- } /* }}} */
- PHP_MINFO_FUNCTION(reflection) /* {{{ */
- {
- php_info_print_table_start();
- php_info_print_table_header(2, "Reflection", "enabled");
- php_info_print_table_row(2, "Version", "$Id$");
- php_info_print_table_end();
- } /* }}} */
- zend_module_entry reflection_module_entry = { /* {{{ */
- STANDARD_MODULE_HEADER,
- "Reflection",
- reflection_ext_functions,
- PHP_MINIT(reflection),
- NULL,
- NULL,
- NULL,
- PHP_MINFO(reflection),
- "$Id$",
- STANDARD_MODULE_PROPERTIES
- }; /* }}} */
- /*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * indent-tabs-mode: t
- * End:
- * vim600: noet sw=4 ts=4 fdm=marker
- */
|