Page 1 of 1
Get a list of user defined classes? *Urgent*
Posted: Mon Dec 22, 2008 3:05 pm
by kaisellgren
Hi,
Please anyone have any clues on this: I am trying to get a list of user defined classes. I have a get_declared_classes() but it's not taking params... :/
Re: Get a list of user defined classes? *Urgent*
Posted: Mon Dec 22, 2008 3:34 pm
by andyhoneycutt
Re: Get a list of user defined classes? *Urgent*
Posted: Mon Dec 22, 2008 3:36 pm
by kaisellgren
No that's the one I'm using x) -- and it returns ALL classes...
Re: Get a list of user defined classes? *Urgent*
Posted: Mon Dec 22, 2008 9:01 pm
by Chris Corbyn
You can probably do this with a combination of get_declared_class() and the Reflection API.
Re: Get a list of user defined classes? *Urgent*
Posted: Mon Dec 22, 2008 9:58 pm
by requinix
There are only
a couple predefined classes. Why not use get_declared_classes and just ignore those ones?
Re: Get a list of user defined classes? *Urgent*
Posted: Mon Dec 22, 2008 10:43 pm
by John Cartwright
As far as I know there is no way to distinguish between user defined classes and pre-defined classes. I'd be interested to see how you accomplish this.
Depending on the extensions you have installed, there can be quite a few. Take a look at the user comments in that link for an example.
Re: Get a list of user defined classes? *Urgent*
Posted: Tue Dec 23, 2008 7:17 am
by kaisellgren
It's not enough. For example, custom loaded ZipArchive class is being listed -- which I do not want to list since it's not user made class.
I need to list all user made classes... I'll have a look at the reflection api idea.
Just like Jcart said... I don't see a way to do this, but I'll keep seeking.
Re: Get a list of user defined classes? *Urgent*
Posted: Tue Dec 23, 2008 7:24 am
by Mark Baker
Call get_declared_classes() as the very first action of a script (before any includes, requires, etc), which should give you an array of all the built in classes.
At the point when you need to know, call get_declared_classes() again, and do an array_diff(). This should return only user defined classes.
Won't work if you dynamically load modules that contain additional built-in classes, of course.
Re: Get a list of user defined classes? *Urgent*
Posted: Tue Dec 23, 2008 7:30 am
by kaisellgren
Mark Baker wrote:Call get_declared_classes() as the very first action of a script (before any includes, requires, etc), which should give you an array of all the built in classes.
At the point when you need to know, call get_declared_classes() again, and do an array_diff(). This should return only user defined classes.
Won't work if you dynamically load modules that contain additional built-in classes, of course.
Hey that's rather good idea.
I also noticed that get_declared_classes() returns them so that user classes are in the end. I could build a little list of PHP classes that might be in the end and then see when the user classes start. Of course I would need to try out a few extensions being loaded first ...
Re: Get a list of user defined classes? *Urgent*
Posted: Tue Dec 23, 2008 7:37 am
by Mark Baker
kaisellgren wrote:Of course I would need to try out a few extensions being loaded first ...
They get added to the array in the order they're loaded, so you could end up with an array listing core classes, a number of initial user-defined classes, dynamically-loaded extension classes, yet more user-defined classes...