I want to create a function in PHP and to call it without knowing the function’s name.
Is this possible?
Example:
<?php
$functionName = "someName";
$this->$functionName();
function someName(){
echo("Print Message");
}
?>
It looks like you want
call_user_func().Can be used like the following where the output is the printed message “Hello, World!”:
http://ideone.com/Kw5jp
Note: If you’re using newer versions of PHP, you can also use callables as @J.Bruni pointed out: