Re: Why change require_once? A brief explanation of motives

From: Date: Wed, 18 Jul 2007 11:32:41 +0000
Subject: Re: Why change require_once? A brief explanation of motives
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-47601@lists.php.net to get a copy of this message
Matthew Weier O'Phinney wrote:
On 7/18/07, Lukas Kahwe Smith <mls@pooteeweet.org> wrote:
Alan Knowles wrote:
require_once 'MyPackage/Exception.php; throw new MyPackage_Exception_FileNotFound($thefile);
Well, I do not think that this really qualifies as a good solution.
It's perfectly clear what's happening and why.. looks perfectly good to me ;)
I was not referring to the fact that its not clear, but to the fact that you would have to end up combining a require_once call in all places where you lazy load a class implementation.
More coding, but it's not *that* terrible.
And yet more calls to require_once, whenever you pass through that code. Not sure if this is really a good idea for something that is supposed to be a speed optimization.
I'm agreeing with you here. I think that allfiles.php was very poorly grouped with the call to remove require_once, and many have latched onto the idea that *every* file in a component would be loaded every time -- which would not be the case if an autoloader is present.
Well actually the point is that you can now hand tweak what files to load ahead of time. allfiles.php is just an index of all files that could potentially need to be loaded. it could also be convinient for people running examples or tests. but it will not be used by people that care for performance.
1) IDE's and humans can easily grep for require_once For IDE's I do not know the impact. For humans I think you can just as well grep for "new".
Going back to the example of the singleton above, that's not entirely true. You'd likely need to search for both 'new' and '::'... and '::' is going to be returning false positives once namespaces are released in PHP 6. Better would be the idea of listing dependencies in the class files, and I think that this would be a requirement for acceptance of any stable component.
Yeah, Alan also pointed out that I am missing stuff like class_exists(). I think Alan did also mention instanceOf which no longer triggers __autoload() since PHP 5.1. regards, Lukas

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