title: What are PHP nested functions for?
body: <p>In JavaScript nested functions are very useful: closures, private methods and what have you..</p>
  
  <p>What are nested PHP functions for? Does anyone use them and what for?</p>
  
  <p>Here's a small investigation I did</p>
  
  <pre><code>&lt;?php
  function outer( $msg ) {
      function inner( $msg ) {
          echo 'inner: '.$msg.' ';
      }
      echo 'outer: '.$msg.' ';
      inner( $msg );
  }
  
  inner( 'test1' );  // Fatal error:  Call to undefined function inner()
  outer( 'test2' );  // outer: test2 inner: test2
  inner( 'test3' );  // inner: test3
  outer( 'test4' );  // Fatal error:  Cannot redeclare inner()
  </code></pre>