<?php
class FunctionHolder
{
private $functions;
public function __construct()
{
$this->functions = [];
}
/**
* @param callable $function
* @param string $functionName
* @throws Exception
*/
public function registerFunction($function, $functionName)
{
throw new Exception ('Not a function');
}
$this->functions[$functionName] = $function;
}
/**
* @param string $functionName
* @param array $parameters
*/
public function run($functionName, $parameters)
{
}
}
$functionHolder = new FunctionHolder();
/**
* @param int $number
* @param string $string
*/
$function = function ($number, $string) {
echo "Номер $number";
echo "\nСтрока $string";
};
$functionHolder->registerFunction($function, 'printNumbers');
$functionHolder->run('printNumbers', [12, 'попугай']);
PD9waHAKCmNsYXNzIEZ1bmN0aW9uSG9sZGVyCnsKCiAgICBwcml2YXRlICRmdW5jdGlvbnM7CgogICAgcHVibGljIGZ1bmN0aW9uIF9fY29uc3RydWN0KCkKICAgIHsKICAgICAgICAkdGhpcy0+ZnVuY3Rpb25zID0gW107CiAgICB9CgogICAgLyoqCiAgICAgKiBAcGFyYW0gY2FsbGFibGUgJGZ1bmN0aW9uCiAgICAgKiBAcGFyYW0gc3RyaW5nICRmdW5jdGlvbk5hbWUKICAgICAqIEB0aHJvd3MgRXhjZXB0aW9uCiAgICAgKi8KICAgIHB1YmxpYyBmdW5jdGlvbiByZWdpc3RlckZ1bmN0aW9uKCRmdW5jdGlvbiwgJGZ1bmN0aW9uTmFtZSkKICAgIHsKICAgICAgICBpZiAoIWlzX2NhbGxhYmxlKCRmdW5jdGlvbikpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IEV4Y2VwdGlvbiAoJ05vdCBhIGZ1bmN0aW9uJyk7CiAgICAgICAgfQogICAgICAgICR0aGlzLT5mdW5jdGlvbnNbJGZ1bmN0aW9uTmFtZV0gPSAkZnVuY3Rpb247CiAgICB9CgogICAgLyoqCiAgICAgKiBAcGFyYW0gc3RyaW5nICRmdW5jdGlvbk5hbWUKICAgICAqIEBwYXJhbSBhcnJheSAkcGFyYW1ldGVycwogICAgICovCiAgICBwdWJsaWMgZnVuY3Rpb24gcnVuKCRmdW5jdG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