Re: How PHP handles multiple inclusions of the same file?

From: Date: Tue, 10 Aug 2004 00:16:50 +0000
Subject: Re: How PHP handles multiple inclusions of the same file?
References: 1 2 3 4 5 6 7 8 9  Groups: php.general 
Request: Send a blank email to php-general+get-193236@lists.php.net to get a copy of this message
On Mon, 09 Aug 2004 20:04:50 -0400, Gambler ZG <gambler@highstream.net> wrote: > > Much better to use a *function* which is parsed once > > then include()ing or eval()ing the same code over and over to > (possibly) be > > re-parsed. > > //I read file once: > $handle = fopen($fileName, "r"); > $script = 'function use_cached_code(){ > ?>'; > $script. = fread($handle, filesize($fileName)); > $script. = '<?php > }'; > > //parse it once: > eval($script); > > //and use the code as much as I want: > use_cached_code(); > > > It just makes more sense code structure-wise as well. > > Not in my case, believe me. Otherwise I would not ask about caching. *Maybe* if you *must* use this around *someone else's* code that you are *not allowed* to change would you use this, but I simply don't understand why you would do such a thing. You could add the function name and the bottom part to the file and just include() it. End of problem. If this is a "template" that someone else is editing, I would suggest using a templating system already out there to do the caching and such for you. This is really a nasty hack. If you want to use PHP-style syntax, Savant is your friend. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin--

« previous php.general (#193236) next »