fork download
  1. <?php
  2. class ThisClass {
  3. public static $arguments = array();
  4.  
  5. public static function make_f($arg) {
  6. $variable_name = uniqid();
  7.  
  8. ThisClass::$arguments[$variable_name] = $arg; // Replace ThisClass with the name of the actual class
  9.  
  10. $callback = create_function('$my_var', 'return $my_var * ThisClass::$arguments[\'' . $variable_name . '\'];');
  11.  
  12. return $callback;
  13. }
  14. }
  15.  
  16. $double = ThisClass::make_f(2);
  17. $triple = ThisClass::make_f(3);
  18.  
  19. echo "The double of 16 is " . $double(16) . "\n";
  20. echo "The triple of 20 is " . $triple(20) . "\n";
  21. ?>
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
The double of 16 is 32
The triple of 20 is 60