title: PHP store function in array
body: <p>i want to store function in array</p>
  
  <p>send the array to another page</p>
  
  <p>then execute it</p>
  
  <p>i already read <a href="https://stackoverflow.com/questions/1499862/can-you-store-a-function-in-a-php-array">Can you store a function in a PHP array</a> but still don't know what to do</p>
  
  <p>here's what i try</p>
  
  <p><strong>control.php</strong> (it start here)</p>
  
  <pre><code>&lt;?php
  
      function getFirstFunction(){    echo "first function executed"; }
  
      $data = array();
      $data[0] = getFirstFunction();
      $data[1] = function(){  echo "second function executed";   };
      $data[2] = function(){  require_once "additional.php";    };
      $data[3] = "my string";
  
  
      header('Location: view.php?data='.$data);
  
  ?&gt;
  </code></pre>
  
  <p><strong>additional.php</strong></p>
  
  <pre><code>&lt;?php   echo "additional included"   ?&gt;
  </code></pre>
  
  <p><strong>view.php</strong></p>
  
  <pre><code>&lt;?php
      if( isset($_GET['data']) ){
  
          foreach( $_GET['data'] as $temp ){
              if( is_callable($temp) ){
                  $temp;
  
              }else{
                  "its not a function";
              }
          }
      }
  ?&gt;
  </code></pre>
  
  <p>my error =  </p>
  
  <blockquote>
    <p>Warning: Invalid argument supplied for foreach() in D:\Workspace\Web\latihanns\php\get\view.php on line 4</p>
  </blockquote>
  
  <p><strong>EDIT</strong>
  thanks for notify that <strong>this code its dangerous</strong>.i'm not use this code in real live. i just try to learn store function in array then call it. then i just curious how if i call it on another page. i just simply curious... i make my code look clear and simple here because i afraid if i wrote complicated code, no one will be here or my post will closed as too localized...</p>