Re: another question on setting include paths for a project

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Mar 22, 2010 at 10:51:38AM -0400, Robert P. J. Day wrote:

> On Mon, 22 Mar 2010, Richard Quadling wrote:
> 
> > Depending upon what is being included, an autoloader could help
> > here.
> >
> > The main payoffs for autoloading are reduced memory footprint (class
> > are loaded JIT) and no need for each class to know exactly where the
> > other classes are.
> >
> > So, your main page needs to load the autoloader and the autoloader
> > handles the loading of the classes.
> >
> > No need to change the include_path setting.
> 
>   ok, i'm looking at the PHP manual page for autoload, sample:
> 
>   function __autoload($class_name)
>   {
>     require_once $class_name . '.php';
>   }
> 
> and some obvious questions suggest themselves:
> 
> 1) in as simple an example as above, does the include_path still
> control the search?  since i'm not doing anything fancy above in terms
> of specifying *where* that class is defined, it seems that i'll still
> have the same problem to solve, no?

Yep and yep.

> 
> 2) i'm guessing that i can make the __autoload function as
> sophisticated as i want, in that i can have it consult an environment
> variable to determine where to search, but i'm still unsure as to how
> i can set an environment variable to be consulted on the "server"
> side.
> 

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

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux