Re: [Coding Standards] Loading all files at once - Some sample code
| From: | Philippe Jausions | Date: | Tue, 10 Jul 2007 15:39:01 +0000 |
| Subject: | Re: [Coding Standards] Loading all files at once - Some sample code | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-47401@lists.php.net to get a copy of this message | ||
Paul M Jones wrote:
> The proposed coding standard states:
>
>> Loading all files at once
>>
>> PEAR2/PackageName/allfiles.php is the "load all classes at once for
>> easy startup and opcode caches friendliness" so that, for instance,
>> the file might contain:
>>
>> <?php
>> // note the lack of dependency on include_path - essential for
>> beginners
>> if (!class_exists(PEAR2_Exception)) {
>> class PEAR2_Exception extends Exception {}
>> }
>> require dirname(__FILE__) . '/Base.php';
>> require dirname(__FILE__) . '/Exception.php';
>> require dirname(__FILE__) . '/Drivers/Common.php';
>> require dirname(__FILE__) . '/Drivers/Simple.php';
>> require dirname(__FILE__) . '/Drivers/Fancy.php';
>> ?>
>
> I don't think this should be a *requirement* at all. I agree that
> developers who *want* to provide this kind of functionality should abide
> by a standard way of doing it, but making it a requirement for each
> package seems like overkill to me (esp. for very large packages with
> adapters and plugin systems, like Text_Wiki and MDB2). I have heard the
> "it makes things easier for opcode caches" argument, but I don't find it
> especially strong.
>
> This seems very much like a "recipe" or "practice" candidate to me, not
> a coding standard by which package acceptance or denial will be judged.
>
>
Just throwing some sample code in the discussion, otherwise we're just
blowing air.
http://pear.11abacus.com/dev/PEAR2_Benchmark/loadClass.phps
If someone could put some benchmark tests with it, using the various
properties, and running a reasonable set of PEAR packages (good start
would be to use Text_Wiki, MDB2 and HTML_QuickForm) with all the
require_once replaced with PEAR2_Load::loadClass(), and against the same
set of PEAR packages without neither require_once nor
PEAR2_Load::loadClass() calls at all, but the allfiles.php instead.
Target would be PHP 5.2+ with and without opcode cache.
Whoever puts the test suite together, please make the source available
to all. (I just contribute this small piece of code for now)
-Philippe