tonelm54
asked on
Load extension classes
Im trying to write a site, where I want to be able to add extensions into it at a later date. I want to loop over a folder and include each file in the folder which I can do easily. My problem is how to list all available classes that Ive loaded.
So what Ive come up with is a simple test which loads all available classes before, then reads a class, reads all available classes and then looks at the 2 arrays and displays the differences which should be just my class:-
However all I get is an empty array back.
Anyone got any ideas how to fix this, or if anyone has any ideas how I can simply load extensions by putting files into a folder?
Thanks in advance
So what Ive come up with is a simple test which loads all available classes before, then reads a class, reads all available classes and then looks at the 2 arrays and displays the differences which should be just my class:-
<?php
$startupClasses = get_declared_classes();
class testMe {
public function __construct() {
}
}
$endClasses = get_declared_classes();
$availableClasses = array_diff($startupClasses,$endClasses);
print_r($availableClasses);
?>
However all I get is an empty array back.
Anyone got any ideas how to fix this, or if anyone has any ideas how I can simply load extensions by putting files into a folder?
Thanks in advance
ASKER
I have looked at these, but there isn't a way to list what classes are loaded.
What I want to do is have a page which loads all the available files from the directory then list the classes. In each of the classes have a function for description, settings etc so the user can setup the class when required.
What I want to be able to do is just drop the class file into the directory and then to be able to list the classes it and other included files load.
What I want to do is have a page which loads all the available files from the directory then list the classes. In each of the classes have a function for description, settings etc so the user can setup the class when required.
What I want to be able to do is just drop the class file into the directory and then to be able to list the classes it and other included files load.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think (though I have not tested any) that you may find solutions in the user-contributed notes here. There seem to be some fairly strict file naming conventions, and that is probably good!
http://php.net/manual/en/function.spl-autoload-register.php
http://php.net/manual/en/function.spl-autoload-register.php
Thanks for the points. I'd be interested to know what output you get when you run that script. If you would be so kind as to copy the var_dump() output and paste it into the code snippet, it would be really helpful to me. Thanks, ~Ray
http://php.net/manual/en/language.oop5.autoload.php
http://php.net/manual/en/function.autoload.php
http://php.net/manual/en/function.spl-autoload-register.php
For performance reasons, I have avoided using autoload(). I find that it is better for performance to load all of the class definitions in a single "common.php" file. Your build process can compose the common script from your development or deployment libraries. Fewer disk read operations means shorter time to load the scripts and render the web pages.