Reflection and used classes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hugh Oxford

    Reflection and used classes

    Hi Folks,

    Is there any way of using reflection to find out what classes other
    classes use?

    I do not mean which classes extend other classes, I mean within methods,
    for example, where the "new" keyword instantiates objects of other classes.

    Any ideas?
  • petersprc

    #2
    Re: Reflection and used classes

    Hi,

    Don't know of a way to this with reflection.

    You can use PHPXref to locate references to a particular class, or you
    could try a recursive grep for a class identifier.

    Regards,

    John Peters

    On Apr 25, 2:37 pm, Hugh Oxford <ares...@fas.co mwrote:
    Hi Folks,
    >
    Is there any way of using reflection to find out what classes other
    classes use?
    >
    I do not mean which classes extend other classes, I mean within methods,
    for example, where the "new" keyword instantiates objects of other classes.
    >
    Any ideas?

    Comment

    • Hugh Oxford

      #3
      Re: Reflection and used classes

      petersprc wrote:
      Hi,
      >
      Don't know of a way to this with reflection.
      >
      You can use PHPXref to locate references to a particular class, or you
      could try a recursive grep for a class identifier.
      >
      Regards,
      >
      John Peters
      >
      I like PHPxref, the problem is I use autoload. Maybe I could look at the
      code.

      Comment

      • Alexey Kulentsov

        #4
        Re: Reflection and used classes

        Hugh Oxford wrote:
        Is there any way of using reflection to find out what classes other
        classes use?
        >
        I do not mean which classes extend other classes, I mean within methods,
        for example, where the "new" keyword instantiates objects of other classes.
        >
        Any ideas?
        Sorry, but in languages like PHP here is no way to do such things
        reliably. This is real code from my current project:

        <CODE>
        ....
        $classname=self ::getClassName( $classId);
        $filename=strto lower($classId. '.object.php');

        include_once $filename;

        $object= new $classname($thi s,$parentId,$na me);
        ....
        </CODE>

        Class names taken from XML file. So if you have case like this and
        PHPxref is not enough for you - I think here are tools to do this as you
        want.

        Comment

        Working...