title: Create and call a function inside a class method
body: <p>I am trying to call a function inside a function but it is not getting called and no error is coming up.</p>
  
  <p>I created a <code>$addFile</code> function to reuse it in the switch statement below. </p>
  
  <pre><code>public function findFilesBySize($path, $size)
  {
      if((!is_array($size)) || (count($size) != 2))
          throw new \Exception("Second parameter should be array of comparison operator and value", 1);
  
  
      $path = (is_dir($path)) ? $path : getcwd();
      $files = array();
      $addFiles = function(array $files, \DirectoryIterator $file ) 
                  {
                      die('working'); // function not getting called
                      $files[] = $file-&gt;getFileName();
                  };
      $iterator = new \DirectoryIterator($path);
      foreach ($iterator as $file) {
          if($file-&gt;isDir())
              continue;
          switch ($size[0]) {
              case '&lt;':
                  if($file-&gt;getSize() &lt; $size[1]) {
                      $addFiles($files, $file);
                  }
                  break;   
              case '&gt;':
                  if($file-&gt;getSize() &gt; $size[1]) {
                      $addFiles($files, $file);
                  }
                  break;
  
              default:
                  # code...
                  break;
          }
      }
      return $files;
  }
  </code></pre>
  
  <p><strong>Additional/Optional Part:</strong>
  I don't like the switch approach and if somebody can suggest any good approach to do the <code>if($file-&gt;getSize() $operator $value)</code> then please let me know.</p>