Get a list of user defined classes? *Urgent*
Moderator: General Moderators
- kaisellgren
- DevNet Resident
- Posts: 1675
- Joined: Sat Jan 07, 2006 5:52 am
- Location: Lahti, Finland.
Get a list of user defined classes? *Urgent*
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... :/
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... :/
Last edited by kaisellgren on Mon Dec 22, 2008 3:37 pm, edited 1 time in total.
- andyhoneycutt
- Forum Contributor
- Posts: 468
- Joined: Wed Aug 27, 2008 10:02 am
- Location: Idaho Falls
- kaisellgren
- DevNet Resident
- Posts: 1675
- Joined: Sat Jan 07, 2006 5:52 am
- Location: Lahti, Finland.
Re: Get a list of user defined classes? *Urgent*
No that's the one I'm using x) -- and it returns ALL classes...andyhoneycutt wrote:Maybe this is what you're looking for?
http://us.php.net/manual/en/function.ge ... lasses.php
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Get a list of user defined classes? *Urgent*
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*
There are only a couple predefined classes. Why not use get_declared_classes and just ignore those ones?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Get a list of user defined classes? *Urgent*
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.tasairis wrote:There are only a couple predefined classes. Why not use get_declared_classes and just ignore those ones?
- kaisellgren
- DevNet Resident
- Posts: 1675
- Joined: Sat Jan 07, 2006 5:52 am
- Location: Lahti, Finland.
Re: Get a list of user defined classes? *Urgent*
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.tasairis wrote:There are only a couple predefined classes. Why not use get_declared_classes and just ignore those ones?
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.
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: Get a list of user defined classes? *Urgent*
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.
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.
- kaisellgren
- DevNet Resident
- Posts: 1675
- Joined: Sat Jan 07, 2006 5:52 am
- Location: Lahti, Finland.
Re: Get a list of user defined classes? *Urgent*
Hey that's rather good idea.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.
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 ...
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: Get a list of user defined classes? *Urgent*
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...kaisellgren wrote:Of course I would need to try out a few extensions being loaded first ...