Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 8th, 2012  |  syntax: PHP  |  size: 0.43 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. class Foo
  4. {
  5.   public function bar()
  6.   {
  7.     $baz = 1;
  8.     $qrz = 2;
  9.        
  10.     $name_of_fnc = function($name_of_func) use($bar, $qrz) {
  11.       $res = $baz + $qrz;
  12.      
  13.       if ($res > 10) return $res;
  14.      
  15.       $baz++;
  16.       $qrz++;
  17.  
  18.       return $name_of_fnc();
  19.     };
  20.  
  21.     return function() {
  22.        $name_of_fnc($name_of_fnc);
  23.     };
  24.   }
  25. }
  26.  
  27. $foo = new Foo;
  28. print call_user_func($foo->bar()); // 11