Created
March 19, 2012 01:21
-
-
Save mgng/2089022 to your computer and use it in GitHub Desktop.
call_user_func
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function unko(&$param){ $param++; } | |
$func = 'unko'; | |
$param1 = 1; | |
$param2 = 1; | |
call_user_func($func, $param1); | |
call_user_func($func, $param1); | |
call_user_func($func, $param1); | |
echo $param1; // 1 | |
$func($param2); | |
$func($param2); | |
$func($param2); | |
echo $param2; // 4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Foo{ | |
public static function bar($s){ | |
return "{$s}なう"; | |
} | |
} | |
$class = "Foo::bar"; | |
$param = 'うんこ'; | |
echo call_user_func($class, $param); // うんこなう | |
echo $class($param); // Fatal error: Call to undefined function Foo::bar() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment