Is it better to eval dynamically-generated code or store it in a temp file and include it?
<p>Sometimes I need to create PHP code for formatting arrays on the fly. one way to do this is to use <code>eval</code>. but I think of writing the generated code to a PHP file and then include it. This has many advantages to <code>eval</code>, one of them is caching of generated code. But I haven't seen such a practice in other code. I don't know if there's any problem regarding security or other things with this?</p>

<p>This is an example:</p>

<pre><code>&lt;?php

$code = '&lt;? foreach($rows as $row) {$row["insertion"] = format($row["insertion"]);} ?&gt;'
file_put_contents('formatter.php', $code);
include('formatter.php');

?&gt;
</code></pre>

<p>I just want to know is it good to create a PHP file on the fly and then include it?</p>

<p>Or is it better to just go ahead and <code>eval()</code> the code directly, with no stored history?</p>
