Inline code with require vs. function call
<p>I wonder if I should write a function for a specific problem (e.g. <code>function specific()</code>) or if I should give this piece of code into one php script and call <code>require 'specific.php'</code> when needed?</p>

<p>The specific problem I'm talking is about processing a filled form requested via POST and then redirecting the browser because of the PRG (Post/Redirect/Get) pattern (which includes, that <code>exit</code> will be called and the code isn't continued after the <code>require</code> respectively function call). The code for processing the request is needed in two scripts. Consider following code:</p>

<p>somePage.php</p>

<pre><code>require 'process_form_fnc.php'; // for Variant 2

if($_SERVER['REQUEST_METHOD'] == 'POST')
{
    // process filled form
    require 'process_form.php'; // Variant 1
    process_form_fnc();         // or Variant 2
}
</code></pre>

<p>Would you choose the function or the require variant (and why)?</p>
