Reflection API idea

php.internals

Bob Silva

20 years ago
Here's an idea for the maintainer of the Reflection API, to be able to view the class a method is defined in (if not overridden). class Vehicle { function go() {} function crash() {} } class Car extends Vehicle { function crash() {} function collectInsurance() {} } class Ford extends Car { function fixOrRepairDaily() {} } Reflection::export(new ReflectionClass(Car)); Class [ <user> class Ford extends Car ] { - Methods [4] { Method [ <user> public method fixOrRepairDaily ] { } Method [ <user> public method crash inherited from Car ] { } Method [ <user> public method collectInsurance inherited from Car ] { } Method [ <user> public method go inherited from Vehicle ] { } } I am developing on a Windows machine so a Unified Patch isn't easily attainable (with the tools I have at least). Psuedo Patch: Modify _function_string in zend_reflection_api.c to take a zend_class_entry of the reflecting class or NULL if not used in a class context. Then add the "inherited from" section as below (or however you'd like to implement). string_printf(str, "%s", fptr->common.function_name); if (fptr->common.scope && memcmp(fptr->common.scope->name, ce->name)) { string_printf(str, " inherited from %s", fptr->common.scope->name); } string_printf(str, " ] {\n"); Not sure if this works in all situations, I'll leave that for you guys to determine if you think this is useful functionality. Bob Silva

Bob Silva

20 years ago
Whoops, that memcmp should be a strcmp.

Marcus Börger

20 years ago
Hello Bob, have you looked at head output of Reflection lately? I guess that contains all you want, right? marcus Wednesday, November 23, 2005, 5:19:10 AM, you wrote:
> Here's an idea for the maintainer of the Reflection API, to be able to view > the class a method is defined in (if not overridden).
> class Vehicle { > function go() {} > function crash() {} > }
> class Car extends Vehicle { > function crash() {} > function collectInsurance() {} > }
> class Ford extends Car { > function fixOrRepairDaily() {} > }
> Reflection::export(new ReflectionClass(Car));
> Class [ <user> class Ford extends Car ] { > > - Methods [4] { > Method [ <user> public method fixOrRepairDaily ] { > }
> Method [ <user> public method crash inherited from Car ] { > }
> Method [ <user> public method collectInsurance inherited from Car ] { > }
> Method [ <user> public method go inherited from Vehicle ] { > } > }
> I am developing on a Windows machine so a Unified Patch isn't easily > attainable (with the tools I have at least).
> Psuedo Patch: > Modify _function_string in zend_reflection_api.c to take a zend_class_entry > of the reflecting class or NULL if not used in a class context. > Then add the "inherited from" section as below (or however you'd like to > implement).
> string_printf(str, "%s", fptr->common.function_name); > if (fptr->common.scope && memcmp(fptr->common.scope->name, ce->name)) { > string_printf(str, " inherited from %s", fptr->common.scope->name); > } > string_printf(str, " ] {\n");
> Not sure if this works in all situations, I'll leave that for you guys to > determine if you think this is useful functionality.
> Bob Silva
Best regards, Marcus

Bob Silva

20 years ago
Nope, sorry, I'll do my homework next time. Bob

Jared Williams

20 years ago
Hi, This has been do-able in PHP5 for somewhile, (wrote a reflection browser while ago to show such things) http://www.ren.dotgeek.org/classbrowser/?class=DOMCdataSection Jared

Marcus Börger

20 years ago
Hello Jared, hey cool stuff! Any chance you could publish this or make it a PEAR class or put it into the newly created Reflection extension as example? best regards marcus Wednesday, November 23, 2005, 12:50:25 PM, you wrote:
> Hi, > This has been do-able in PHP5 for somewhile, (wrote a reflection > browser while ago to show such things) > http://www.ren.dotgeek.org/classbrowser/?class=DOMCdataSection
> Jared > >> Here's an idea for the maintainer of the Reflection API, to >> be able to view the class a method is defined in (if not overridden). >> >> >> class Vehicle { >> function go() {} >> function crash() {} >> } >> >> class Car extends Vehicle { >> function crash() {} >> function collectInsurance() {} >> } >> >> class Ford extends Car { >> function fixOrRepairDaily() {} >> } >> >> Reflection::export(new ReflectionClass(Car)); >> >> >> Class [ <user> class Ford extends Car ] { >> >> - Methods [4] { >> Method [ <user> public method fixOrRepairDaily ] { >> } >> >> Method [ <user> public method crash inherited from Car ] { >> } >> >> Method [ <user> public method collectInsurance inherited >> from Car ] { >> } >> >> Method [ <user> public method go inherited from Vehicle ] { >> } >> } >> >> I am developing on a Windows machine so a Unified Patch isn't >> easily attainable (with the tools I have at least). >> >> Psuedo Patch: >> Modify _function_string in zend_reflection_api.c to take a >> zend_class_entry of the reflecting class or NULL if not used >> in a class context. >> Then add the "inherited from" section as below (or however >> you'd like to implement). >> >> string_printf(str, "%s", fptr->common.function_name); if >> (fptr->common.scope && memcmp(fptr->common.scope->name, ce->name)) { >> string_printf(str, " inherited from %s", >> fptr->common.scope->name); } string_printf(str, " ] {\n"); >> >> >> Not sure if this works in all situations, I'll leave that for >> you guys to determine if you think this is useful functionality. >> >> Bob Silva >> >> -- >> PHP Internals - PHP Runtime Development Mailing List To >> unsubscribe, visit: http://www.php.net/unsub.php >>
Best regards, Marcus

Jared Williams

20 years ago
Hi,
> hey cool stuff! Any chance you could publish this or make > it a PEAR class or put it into the newly created Reflection > extension as example?
http://sourceforge.net/projects/phpclassbrowser/ Its in CVS at sourceforge. (Still haven't gotten around to reading up on how to create file packages on SF) http://cvs.sourceforge.net/viewcvs.py/phpclassbrowser/classbrowser/ Need to update it sometime one of the parameter required column needs to go now as bug #29523 is fixed. Jared