Is PHP's include resource-expensive (particularly during iterations)?

Viewed 1216

Does PHP cache include requests? I was wondering how to clean up my code and I thought about using a bit more includes. Consider the following scheme.

[foreach answer] [include answer.tpl.php] [/foreach]

This would require to include answer.tpl.php hundreds of times.

Does it cache? Will it have a worth-considering affect on performance? Is that considered a good practice? Bad?

In response to @Aaron Murray answer

No, that won't work. The mere concept of _once is to prevent including the same file more than once. (to prevent errors caused by e.g. overwriting constant values)

Practical example would look like this:

# index.php
<?php
$array  = array('a', 'b', 'c');

$output = '';

foreach($array as $e)
{
    $output .= require_once 'test.php';
}

echo $output;

# test.php 
<?php
return $e;
3 Answers
Related