fork(1) download
  1. <?php
  2.  
  3. function isgreater($a, $b) {
  4. if($a > $b)
  5. return 1;
  6. else
  7. return 0;
  8. }
  9.  
  10. //function only can pass value or reference, eg: function xxx(2, isgreater)
  11. //compare with c programming, php is no datatype define, so the function can pass to it //directly.
  12. function compare($num1, $num2, &$func) {
  13.  
  14. //$funcpointer = & $func;
  15.  
  16. //return $funcpointer($num1, $num2);
  17.  
  18. return $func($num1, $num2);
  19.  
  20. }
  21.  
  22. $num1 = 100;
  23. $num2 = 50;
  24.  
  25.  
  26. if(compare($num1, $num2, isgreater))
  27. printf("num1 is greater than num2");
  28.  
  29. ?>
Runtime error #stdin #stdout 0.02s 13664KB
stdin
Standard input is empty
stdout
Fatal error: Only variables can be passed by reference in /home/KhJfGg/prog.php on line 26