php - Inline code with require vs. function call -


i wonder if should write function specific problem (e.g. function specific()) or if should give piece of code 1 php script , call require 'specific.php' when needed?

the specific problem i'm talking processing filled form requested via post , redirecting browser because of prg (post/redirect/get) pattern (which includes, exit called , code isn't continued after require respectively function call). code processing request needed in 2 scripts. consider following code:

somepage.php

require 'process_form_fnc.php'; // variant 2  if($_server['request_method'] == 'post') {     // process filled form     require 'process_form.php'; // variant 1     process_form_fnc();         // or variant 2 } 

would choose function or require variant (and why)?

using require insert arbitrary code blocks @ current location bad hackish (even though not uncommon). prefer keep code in functions.

you can find similar discussions c (#include arbitrary code snippets vs. functions), same arguments , equally clear consensus.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -