Re: [PHP] another question on setting include paths for a project

[email protected] (Richard Quadling)
Newsgroups php.general
Message-ID <[email protected]>
On 22 March 2010 15:28, [email protected] <[email protected]> wrote:
> On 3/22/10 10:25 AM, Paul M Foster wrote:
>
>> That's the key. You can do anything you want inside __autoload(). If you
>> must consult something in the environment, there are a couple of ways to
>> do it. First, set a variable in the $_SESSION array, and consult it in
>> __autoload(). Second, use a configuration file for your application.
>> Have it in a stable place, and read the values out of it as needed.
>> Consult these in your __autoload() if you like.
>>
>> Paul
>
> I'd suggest skipping __autoload() and going straight for
> spl_autoload_register(), as it does the same thing but is more flexible
> since you can then have multiple autoload callbacks if necessary.
>
> --Larry Garfield
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Completely agree with Larry here. spl_autoload_register is __autoload++.

Essentially, the autoloader knows where it is and should know where
everything else it is expected to load is.

Having a naming convention that say maps class name to file path/name
(Zend_Soap_Wsdl_Exception maps to ./Zend/Soap/Wsdl/Exception.php) and
sticking with it allows for a single autoloader to be used for any
root name.

Autoloading only really works out-the-box with classes. There has been
discussion on making this work with functions and namespaces.



-- 
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.