Re: Mixing eval() with include/require
| From: | Mark Rogers | Date: | Fri, 22 Dec 2000 09:27:35 +0000 |
| Subject: | Re: Mixing eval() with include/require | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-31554@lists.php.net to get a copy of this message | ||
"Ignacio Vazquez-Abrams" wrote:
> Try:
>
> <?php
> function Test($id)
> {
> for ($i=0; $i<1000; ++$i)
> include("test$id.inc");
> };
> ?>
>
> include()s can be dynamic that way; AFAIK require()s can't.
The problem is that the code in the include file is being used to process
each line of an input file, and that input file will have 100,000 lines or
so, so I need to reduce the overhead as much as possible. The method you
suggest will re-read the include file on each parse, which is slower than
reading it once and building a function out of it.
It also has the interesting side effect that if you change the include file
part way through the process, the results also change part way through (not
good in this case).
The workaround I'm using at the moment puts function headers into the
include file, so test1.inc becomes
function testfunc1() {
/* previous contents of include file here */
}
Test() then has include_once('test1.inc') in it. I had wanted to avoid this
method (it is too inflexible) but it works quite well.