Re: Critical Thinking, or Several "Why" Questions

From: Date: Wed, 06 Apr 2005 02:33:32 +0000
Subject: Re: Critical Thinking, or Several "Why" Questions
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-212337@lists.php.net to get a copy of this message
* GamblerZG <gambler@highstream.net>: > > What fancy logic? And why does no one need it? > > I'm referring to this: > http://archives.devshed.com/a/ng/557-22943/ Interestingly, I didn't see the so-called optimized code posted for public consumption. If the person who started that thread was serious, s/he should submit it to the PHP developers for review -- or become a PHP developer. Heresay like that gets nobody anywhere. As for the 'fancy logic', include_once does, among other things: * Checks to see if the requested file has been include'd once already * Checks to determine if the include path has changed since the last time it was include'd * If the include path *has* changed, stats the file to determine if it's actually different A sample use: I'm in a class. In the class, each method represents a different run mode, or screen, of an application: splash screen, listing of resources, form for searching, form for adding a resource, etc. For each dependency, I could 'require_once' a file, or simple 'require' it, but here's the deal: I want to lazy load my dependencies. If I'm showing the splash page, I don't necessarily want to load my pagination class or my validation class. Likewise, I'm hesitant about include'ing these files, because I may have other files elsewhere in the execution chain that will also be loading them -- and that could cause errors (redefining a class or function). 'include_once' allows me to lazy load -- and thus optimize my application. Sure, it may be a slight performance hit -- but not nearly that of loading the files in question. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association | http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:matthew@garden.org | http://vermontbotanical.org

« previous php.general (#212337) next »