Re: [Coding Standards] Loading all files at once

From: Date: Fri, 13 Jul 2007 13:47:00 +0000
Subject: Re: [Coding Standards] Loading all files at once
References: 1 2 3 4 5 6 7 8 9 10 11 12  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-47465@lists.php.net to get a copy of this message
Lukas Kahwe Smith wrote: > Matthew Weier O'Phinney wrote: >> On 7/12/07, Lukas Kahwe Smith <mls@pooteeweet.org> wrote: >>> > >>> > * It's hard to verify that require_once is or is not the bottleneck, >>> > as results vary based on environment and methodology >>> > * Regardless, the performance gain, if any, is not huge >>> > * Many are upset with the proposal, on many grounds including: >>> > * seems like a rewrite of PHP (!class_exists() hack) that could >>> > lead >>> > to a situation similar to the PEAR::isError() situation (i.e., if >>> > PHP changes to be more performant or correct the situation, new >>> > standards and changes would need to be made, whereas using >>> > existing PHP functionality would not) >>> >>> I do not think that the impact is debatable at all to the "speed >>> freak" faction. Modification of code at install time is not the way >>> to go. It will cause all sorts of uncertainties during deployment >> >> Certainly, 15% is a sufficient enough gain to warrant making a change. >> However, whether or not this should be the job of PEAR instead of a >> build tool is debatable. Build tools are much better suited for this. > > I very much disagree. If we modify code at install time, it will be a > maintenance nightmare, things will stop working as users copy around > code. Its a recipe for desaster since the changes are subtle. I was all > for exploring some auto E_STRICT conversion tool because the changes > would be super obvious and there was no reasonable way to do it back > then. I do not see this case here. > > Furthermore there are tricky code constructs for loading drivers in many > of our modules. These you will not be able to adapt with an installer, > unless we really figure out a standardized way of doing those. > > regards, > Lukas I think a very simple way to do exactly this is: try { PEAR2_Load::loadClass($className); $instance = new $className(); catch ($e PEAR2_Load_ClassNotFoundException) { // Attempt another fall back, driver } the try block is of course optional, but for those package that can't let a driver class not exists, the catch is simple. This way we get rid of all the different implementations of factory methods, and give even more control back to the user (i.e. why not let the exception bubble up and let the application take care of reporting the error or choosing a different driver.) This makes a no brainer to comment out the PEAR2_Load::loadClass() call, and it doesn't break the package. It doesn't even change the line count for easier debugging! -Philippe

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