FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Discovering all sub-classes via introspection?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Discovering all sub-classes via introspection? [message #171509] Fri, 07 January 2011 03:38 Go to next message
Roy Smith is currently offline  Roy Smith
Messages: 11
Registered: November 2010
Karma: 0
Junior Member
Given a class, is there a way to find all the classes which extend it?
Re: Discovering all sub-classes via introspection? [message #171510 is a reply to message #171509] Fri, 07 January 2011 03:40 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 1/6/2011 10:38 PM, Roy Smith wrote:
> Given a class, is there a way to find all the classes which extend it?

No. There is no way to know if ANY class extends it, unless the class
has been instantiated.

A basic concept of OO programming - derived classes know about the base
class, but base classes don't know anything about derived classes.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Discovering all sub-classes via introspection? [message #171512 is a reply to message #171509] Fri, 07 January 2011 04:08 Go to previous messageGo to next message
Sherm Pendley is currently offline  Sherm Pendley
Messages: 33
Registered: September 2010
Karma: 0
Member
Roy Smith <roy(at)panix(dot)com> writes:

> Given a class, is there a way to find all the classes which extend it?

Use get_declared_classes() to get a list of classes, then loop over
the list and use is_subclass_of() on each item to check if it extends
your target class.

sherm--

--
Sherm Pendley
<http://camelbones.sourceforge.net>
Cocoa Developer
Re: Discovering all sub-classes via introspection? [message #171519 is a reply to message #171512] Fri, 07 January 2011 13:15 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 1/6/2011 11:08 PM, Sherm Pendley wrote:
> Roy Smith<roy(at)panix(dot)com> writes:
>
>> Given a class, is there a way to find all the classes which extend it?
>
> Use get_declared_classes() to get a list of classes, then loop over
> the list and use is_subclass_of() on each item to check if it extends
> your target class.
>
> sherm--
>

Which only works if you have included all the files containing the
derived classes.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Discovering all sub-classes via introspection? [message #171541 is a reply to message #171519] Sat, 08 January 2011 14:57 Go to previous messageGo to next message
RMP is currently offline  RMP
Messages: 6
Registered: December 2010
Karma: 0
Junior Member
Am 07.01.2011 14:15, schrieb Jerry Stuckle:
> On 1/6/2011 11:08 PM, Sherm Pendley wrote:
>> Roy Smith<roy(at)panix(dot)com> writes:
>>
>>> Given a class, is there a way to find all the classes which extend it?
>>
>> Use get_declared_classes() to get a list of classes, then loop over
>> the list and use is_subclass_of() on each item to check if it extends
>> your target class.
>>
>> sherm--
>>
>
> Which only works if you have included all the files containing the
> derived classes.
>

Maybe you'll find something in the Reflection of PHP (>5):
http://de3.php.net/manual/de/book.reflection.php

There you find Reflection::getExtension and
Reflection::getInterfaceNames which could solve it.

--
greetings,

rmp
Re: Discovering all sub-classes via introspection? [message #171542 is a reply to message #171541] Sat, 08 January 2011 16:34 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 1/8/2011 9:57 AM, _RMP wrote:
> Am 07.01.2011 14:15, schrieb Jerry Stuckle:
>> On 1/6/2011 11:08 PM, Sherm Pendley wrote:
>>> Roy Smith<roy(at)panix(dot)com> writes:
>>>
>>>> Given a class, is there a way to find all the classes which extend it?
>>>
>>> Use get_declared_classes() to get a list of classes, then loop over
>>> the list and use is_subclass_of() on each item to check if it extends
>>> your target class.
>>>
>>> sherm--
>>>
>>
>> Which only works if you have included all the files containing the
>> derived classes.
>>
>
> Maybe you'll find something in the Reflection of PHP (>5):
> http://de3.php.net/manual/de/book.reflection.php
>
> There you find Reflection::getExtension and
> Reflection::getInterfaceNames which could solve it.
>

Which still only works if you have included all the files containing the
derived classes.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Discovering all sub-classes via introspection? [message #171543 is a reply to message #171541] Sat, 08 January 2011 18:02 Go to previous message
Robert Hairgrove is currently offline  Robert Hairgrove
Messages: 19
Registered: September 2010
Karma: 0
Junior Member
On 01/08/2011 03:57 PM, _RMP wrote:
> There you find Reflection::getExtension and
> Reflection::getInterfaceNames which could solve it.

The English version is here:
http://www.php.net/manual/en/book.reflection.php
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Kobweb Java Supplementary 2011 Online Module
Next Topic: phpmailer
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 12:53:55 GMT 2024

Total time taken to generate the page: 0.02293 seconds