Re: autoload, include_once naming conventions

From: Date: Thu, 17 Mar 2005 21:53:34 +0000
Subject: Re: autoload, include_once naming conventions
References: 1 2 3  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-36730@lists.php.net to get a copy of this message
Lukas Smith wrote:
while talking with Derick about what we dont like about PHP5 in Budapest I got an idea ... Basically what if we would replace all (require|include)_once calls with a static PEAR method. This method would get a class name passed and would simply do an class_exists() call and if the class do include the code by replacing "_" to "/".
This sounds very much like what I'm doing with the Solar project (http://solarphp.com). You make the call like this: // will look for Some/Class/Name.php $obj = Solar::object('Some_Class_Name');
I wouldnt want this static method to return an instance of an object. it should only be concerned with ensuring that the requested class is defined or delegate the task to __autoload() if defined.
Yes, the widely varying differences in constructor parameters from class to class in PEAR would make this approach difficult for PEAR. With Solar, you get exactly one constructor parameter (an associative array) for any class, which makes it very easy to get back a customized object using the Solar::object() call. From the above example, you would do something like this:
    $config = array('foo' => 'bar', 'baz' => 'dib');
    $obj = Solar::object('Some_Class_Name', $config);
This is the way DB_Table and Text_Wiki work; i.e., with a single constructor param. -- pmj

« previous php.pear.dev (#36730) next »