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

From: Date: Mon, 09 Aug 2004 17:56:50 +0000
Subject: Re: How PHP handles multiple inclusions of the same file?
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-193216@lists.php.net to get a copy of this message
On Mon, 09 Aug 2004 02:11:14 -0400, Gambler ZG <gambler@highstream.net> wrote: > > what do you mean by that? > > Nothing. The statement was based on the erroneous assumption that > anonimous functions allow to go into HTML mode with '?>'. But this will > not stop me, for there is eval()! The general idea is simple - to use > some file's code multiple times without re-reading the file and > re-parsing its content. So... > > $file = "some/script.php"; > $handle = fopen($file, "r"); > $script = fread($handle, filesize($file)); > $script = 'function use_cached_code(){ > ?>'.$script.'<?php > }'; > eval($script); > use_cached_code(); Ick! eval() is evil! What you want here is a function. Make a function which does what you need and call it. function doSomething($val) { //This is "re-used" code echo '$val = '.$val; } > > Ta-dam! Well, I did not actually tested this code, and it's 2:06 AM > here, so I may be wrong, but theoretically it should work. > > -- > 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 (#193216) next »