title: foreach loop that include php files multiple times - acceptable?
body: <p>I have this function "processMessage($msg)" that processes string  based on the first few words in it (prefixes).</p>
  
  <p>I pull lots of rows from the database and pass each $msg string through said function...</p>
  
  <p>The caveat here is that, the function doesn't have the "if($prefix=='blah')" conditions, but rather it includes a bunch of php files that contains these conditions.</p>
  
  <p>Why?</p>
  
  <p>Because instead of hard coding a bunch of conditions in one function, I wanted to organize each condition through separate php files for portability, customization etc (Long story here) </p>
  
  <p>So it basically looks like this (keeping code simple):</p>
  
  <p>Main script loads rows from database and puts messages in an array $msg_r then loops through each msg as:</p>
  
  <pre><code>foreach (msg_r as $key=&gt;$msg){
      processMsg($msg);
  }
  </code></pre>
  
  <p>the  actual Processor function :</p>
  
  <pre><code>function processMsg($msg){
  
      $msg_r = explode(" ",$msg); // break apart message based on spaces .. eg. "reboot machine 30"
      //prepare prefixes
      $prefix1 = $msg_r[0];// reboot
      $prefix2 = $msg_r[1];// machine
      $prefix3 = $msg_r[3];// 30
  
      //process the above prefixes.. but instead of hard coding multiple if conditions here, load if else conditions from files. 
      require("condition1.php");
      require("condition2.php");
      require("condition3.php");
      //my actual require code is in a loop that loads all files found in a target directory
  
  
  }
  </code></pre>
  
  <p>the conditions files are basically just php code of an if else condition for each purpose, eg:</p>
  
  <pre><code>if($prefix1 == 'reboot' and $prefix2 == 'machine') {
  // do something
  }
  </code></pre>
  
  <p>So it's a simple setup that seems to work during my tests, but I wonder if this is a "normal" or "acceptable" strategy, or if ya'll can suggest a different approach? </p>
  
  <p>Regards to all </p>