title: PHP How to create simple hook?
body: <p>I already tried to Google how to do this, but I still can't figure it out. How do I create a simple hook inside PHP? Here is what I've tried so far: </p>
  
  <p><strong>wrapper.php</strong> (application starts here)</p>
  
  <pre><code>&lt;?php   require 'core.php';   ?&gt;
  &lt;?php   require 'view.php';   ?&gt;
  </code></pre>
  
  <p><strong>core.php</strong></p>
  
  <pre><code>&lt;?php
  
  $hooks['hook_head'] = array();
  
  //supposed to insert action in $hooks
  function addHook($hookName, $funct){
      global $hooks;
      array_push($hooks[$hookName], $funct);
  }
  
  
  //supposed to execute specific hook
  function executeHook($hookname){
      global $hooks;
      foreach($hooks[$hookname] as $funct){
          call_user_func( $funct );
      }
  }
  
  //supposed to execute action in $hooks when array key = hook_head
  function hook_head(){
      global $hooks;
      if (array_key_exists('hook_head', $hooks)) {
          executeHook( 'hook_head' );
      }
  }
  
  //supposed to execute action in $hooks when array key == hook_footer
  function hook_footer(){
      global $hooks;
      if (array_key_exists('hook_footer', $hooks)) {
          executeHook( 'hook_footer' );
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p><strong>view.php</strong></p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;?php   hook_head();  ?&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;hr /&gt;
  
      &lt;?php
          //add action to hook start here
          $test = function(){    echo "test succeds";    };
          addHook('hook_head', $test);
      ?&gt;
  
      &lt;?php  hook_footer();  ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The code works fine if I insert an action inside <code>$hooks['hook_head']</code>, before I call <code>hook_head()</code>. What I actually am trying to do though, is insert the action after I called <code>hook_head()</code>. How do I do this? </p>