By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,967 Members | 1,687 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,967 IT Pros & Developers. It's quick & easy.

Parsing a PHP file

P: n/a
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

Apr 30 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hm, I just noticed the get_declared_classes() 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.

Apr 30 '07 #2

P: n/a
On 30 Apr 2007 14:09:42 -0700, in comp.lang.php Ryan Govostes
<rg*******@gmail.com>
<11**********************@h2g2000hsg.googlegroups. 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_method_array - Call a user method given with an array of
parameters [deprecated]
call_user_method - Call a user method on an specific object
[deprecated]
class_exists - Checks if the class has been defined
get_class_methods - 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_classes - Returns an array with the name of the defined
classes
get_declared_interfaces - Returns an array of all declared interfaces
get_object_vars - Returns an associative array of object properties
get_parent_class - Retrieves the parent class name for object or class
interface_exists - 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

---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Apr 30 '07 #3

P: n/a
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_classes and I think what you
are trying might be accomplished thusly:

$before = get_defined_classes();

include('file.inc.php');

$declared = array_diff(get_defined_classes(), $before);

print_r($declared);

--
Ra*********@gmail.com

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

P: n/a
C.
On 1 May, 05:19, Rami Elomaa <rami.elo...@gmail.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.

May 1 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.