Parsing a PHP file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ryan  Govostes

    Parsing a PHP file

    In my PHP script, I'd like to examine another PHP file to get
    information on the classes it will define before I include it
    (alternatively, getting a list of the classes after I've included it
    would be fine too). I realize that I could do some regular expressions
    and hope for the best, but my ideal solution has no chance of
    misfiring (e.g. capturing something in a comment or string, or missing
    something because it's on multiple lines).

    My idea at the moment is to pick apart something like Doxygen or GeSHi
    and figure out some simple file parsing, but I think that's pretty
    involved for my aims here. Does anyone have a suggestion?

    Regards,
    Ryan Govostes

  • Ryan  Govostes

    #2
    Re: Parsing a PHP file

    Hm, I just noticed the get_declared_cl asses() function. I could
    probably get a before-and-after list and compare them to figure out
    which classes were added. Any other ideas are still welcome.

    Comment

    • Jeff North

      #3
      Re: Parsing a PHP file

      On 30 Apr 2007 14:09:42 -0700, in comp.lang.php Ryan Govostes
      <rgovostes@gmai l.com>
      <1177967382.067 595.130100@h2g2 000hsg.googlegr oups.comwrote:
      >| In my PHP script, I'd like to examine another PHP file to get
      >| information on the classes it will define before I include it
      >| (alternatively, getting a list of the classes after I've included it
      >| would be fine too). I realize that I could do some regular expressions
      >| and hope for the best, but my ideal solution has no chance of
      >| misfiring (e.g. capturing something in a comment or string, or missing
      >| something because it's on multiple lines).
      >|
      >| My idea at the moment is to pick apart something like Doxygen or GeSHi
      >| and figure out some simple file parsing, but I think that's pretty
      >| involved for my aims here. Does anyone have a suggestion?
      >|
      >| Regards,
      >| Ryan Govostes
      Would any of these be of help
      Table of Contents

      call_user_metho d_array - Call a user method given with an array of
      parameters [deprecated]
      call_user_metho d - Call a user method on an specific object
      [deprecated]
      class_exists - Checks if the class has been defined
      get_class_metho ds - Returns an array of class methods' names
      get_class_vars - Returns an array of default properties of the class
      get_class - Returns the name of the class of an object
      get_declared_cl asses - Returns an array with the name of the defined
      classes
      get_declared_in terfaces - Returns an array of all declared interfaces
      get_object_vars - Returns an associative array of object properties
      get_parent_clas s - Retrieves the parent class name for object or class
      interface_exist s - Checks if the interface has been defined
      is_a - Returns TRUE if the object is of this class or has this class
      as one of its parents
      is_subclass_of - Returns TRUE if the object has this class as one of
      its parents
      method_exists - Checks if the class method exists
      property_exists - Checks if the object or class has a property

      ---------------------------------------------------------------
      jnorthau@yourpa ntsyahoo.com.au : Remove your pants to reply
      ---------------------------------------------------------------

      Comment

      • Rami Elomaa

        #4
        Re: Parsing a PHP file

        Ryan Govostes kirjoitti:
        In my PHP script, I'd like to examine another PHP file to get
        information on the classes it will define before I include it
        (alternatively, getting a list of the classes after I've included it
        would be fine too).
        I'm curious, what would you do with this info?

        Anyway, as you said, there is get_defined_cla sses and I think what you
        are trying might be accomplished thusly:

        $before = get_defined_cla sses();

        include('file.i nc.php');

        $declared = array_diff(get_ defined_classes (), $before);

        print_r($declar ed);

        --
        Rami.Elomaa@gma il.com

        "Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
        usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze

        Comment

        • C.

          #5
          Re: Parsing a PHP file

          On 1 May, 05:19, Rami Elomaa <rami.elo...@gm ail.comwrote:
          Ryan Govostes kirjoitti:
          >
          In my PHP script, I'd like to examine another PHP file to get
          information on the classes it will define before I include it
          (alternatively, getting a list of the classes after I've included it
          would be fine too).
          >
          I'm curious, what would you do with this info?
          >
          me too. I suspect you really want to learn how to use the autoloader
          facility.

          C.

          Comment

          Working...