Page 1 of 1

Best way of __autoload'ing from several folders?

Posted: Sat Dec 20, 2008 1:28 pm
by kaisellgren
Hi there,

I'm interested in knowing how people are __autoload'ing from several different folders. Do you have a class that caches the paths of the files, or do you perhaps do something like database_mysql where _ gets replaced by / and then it becomes database/mysql.php ? or do you setup a static variable or an ini file or ... ? So what is the way you tell your autoload where certain classes are located?

Re: Best way of __autoload'ing from several folders?

Posted: Sat Dec 20, 2008 2:40 pm
by John Cartwright
Typically you would append your library path to the include path using set_include_path(). Then, depending on the naming conventions, you would parse the class name to determine it's filepath. The most common would be http://framework.zend.com/manual/en/cod ... tions.html where underscores are converted to classes. I.e.

Code: Select all

$foo = new Foobar_Database_Mysql();
would look for foobar/database/mysql.php relative to your include path.

Re: Best way of __autoload'ing from several folders?

Posted: Sat Dec 20, 2008 4:32 pm
by kaisellgren
Jcart wrote:Typically you would append your library path to the include path using set_include_path(). Then, depending on the naming conventions, you would parse the class name to determine it's filepath. The most common would be http://framework.zend.com/manual/en/cod ... tions.html where underscores are converted to classes. I.e.

Code: Select all

$foo = new Foobar_Database_Mysql();
would look for foobar/database/mysql.php relative to your include path.
Yea that's what I was first going to do.. It's just that the classnames have to be then foobar_database_mysql :P -- at least no name conflicts this way :)