Re: [Coding Standards] Loading all files at once

From: Date: Tue, 10 Jul 2007 00:14:48 +0000
Subject: Re: [Coding Standards] Loading all files at once
References: 1 2 3 4  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-47348@lists.php.net to get a copy of this message
Joshua Eichorn wrote:
Travis Swicegood wrote:
Howdy... Joshua Eichorn wrote:
Obviously we can't meet everyones needs, but we do want a solution that is better then the current one. An allfiles.php approach might not be that, but obviously status quo isn't any better either.
    
Actually, I think you can meet the needs of everyone. From the benchmark tests I ran, it looks like you can easily have the allfiles for the performance geeks and have all of the currently existing require_once declarations at the top of the file. My tests showed that it was more efficient to do the second request through a require_once than through an if(!class_exists()), so I don't see an issue. Remove the text disallowing all require_once statements, and add code to Pyrus to generate an allfiles.php file. I imagine Greg's going to have it know what type of package it's preparing, so it will be extremely easy for it to create the necessary require_once statements, and for that matter inject the dirname(__FILE__) call into all of the require_onces throughout the code when it creates the unzip and go installs. -Travis -Travis
Can you show an example of what the file would look like. If your talking about something like: if (!class_exists('Class_Name')) { require 'filename'; } Then yes you can meet everyones goals, though there is still the matter of a PEAR2_PATH constant and if the flexibility is worth it.
No - if()'s are not as efficient in an opcode cache as require_once. This means the code would look like these files: <?php // SomePackage/allfiles.php - for opcode cache users or lazy developers with too much RAM ;-) require 'SomePackage/SomeObj.php'; require 'SomePackage/SomeObj2.php'; ?> <?php // SomePackage/SomeObj2.php require_once 'SomePackage/SomeObj.php'; ... the rest of the file The only difference that this introduces is that allfiles needs to be aware of how a package loads itself. This too can be tackled programmatically - scan the files as you're building and keep track of which files it loads, then load them in an order so the require_once returns before the actual inclusion. That would actually be pretty trivial to write, and it removes the burden from the developer. Feel free to consider that an offer of help when you get around to writing that code. The only issue with this is to make sure that the code actually requires only what it needs. This comes down to part of the code review. Imagine all of the bike shedding you'd allow by making the order in which require_once's are placed important. On second thought... ;-) Anyhow, I might end up doing it before Pyrus is to the point it could use it - that'd be kind of a cool tool to have for phing. :-) -Travis

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