Get a list of user defined classes? *Urgent*

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Get a list of user defined classes? *Urgent*

Post 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... :/
Last edited by kaisellgren on Mon Dec 22, 2008 3:37 pm, edited 1 time in total.
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Get a list of user defined classes? *Urgent*

Post by andyhoneycutt »

Maybe this is what you're looking for?

http://us.php.net/manual/en/function.ge ... lasses.php
User avatar
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*

Post by kaisellgren »

andyhoneycutt wrote:Maybe this is what you're looking for?

http://us.php.net/manual/en/function.ge ... lasses.php
No that's the one I'm using x) -- and it returns ALL classes...
User avatar
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*

Post by Chris Corbyn »

You can probably do this with a combination of get_declared_class() and the Reflection API.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Get a list of user defined classes? *Urgent*

Post by requinix »

There are only a couple predefined classes. Why not use get_declared_classes and just ignore those ones?
User avatar
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*

Post 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.
tasairis wrote:There are only a couple predefined classes. Why not use get_declared_classes and just ignore those ones?
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.
User avatar
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*

Post by kaisellgren »

tasairis wrote:There are only a couple predefined classes. Why not use get_declared_classes and just ignore those ones?
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.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Get a list of user defined classes? *Urgent*

Post 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.
User avatar
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*

Post 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 ...
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Get a list of user defined classes? *Urgent*

Post 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...
Post Reply