# Reflection API idea

- Thread: https://externals.io/message/20257
- Original archive: https://news-web.php.net/php.internals/20257
- Started by Bob Silva on 2005-11-23T04:19:10+00:00
- Messages: 5
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #20257 — Bob Silva — 2005-11-23T04:19:10+00:00

URL: https://externals.io/message/20257#20257

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

---

## #20258 — Bob Silva — 2005-11-23T07:58:48+00:00

URL: https://externals.io/message/20257#20258 · In reply to: #20257

Whoops, that memcmp should be a strcmp.

> -----Original Message-----
> From: Bob Silva [mailto:me@bobsilva.com]
> Sent: Tuesday, November 22, 2005 8:19 PM
> To: 'internals'
> Subject: [PHP-DEV] Reflection API idea
> 
> 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

---

## #20260 — Marcus Boerger — 2005-11-23T08:39:23+00:00

URL: https://externals.io/message/20257#20260 · In reply to: #20257

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

---

## #20262 — Jared Williams — 2005-11-23T11:50:25+00:00

URL: https://externals.io/message/20257#20262 · In reply to: #20257

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
> 
> --
>  To 
> unsubscribe, visit: http://www.php.net/unsub.php

---

## #20275 — Marcus Boerger — 2005-11-23T20:12:39+00:00

URL: https://externals.io/message/20257#20275 · In reply to: #20262

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
>  
> > […]




Best regards,
 Marcus
