Re: another question on setting include paths for a project
| From: | Richard Quadling | Date: | Mon, 22 Mar 2010 15:44:21 +0000 |
| Subject: | Re: another question on setting include paths for a project | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-303092@lists.php.net to get a copy of this message | ||
On 22 March 2010 15:28, larry@garfieldtech.com <larry@garfieldtech.com> 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