PhpSandbox\PHPSandbox::defineFunc PHP Méthode

defineFunc() public méthode

You can pass the function $name and $function closure or callable to define, or an associative array of functions to define, which can have callable values or arrays of the function callable and $pass_sandbox flag
public defineFunc ( string | array $name, callable $function, boolean $pass_sandbox = false )
$name string | array Associative array or string of function $name to define
$function callable Callable to define $function to
$pass_sandbox boolean Pass PHPSandbox instance to defined function when called? Default is false
    public function defineFunc($name, $function, $pass_sandbox = false)
    {
        if (is_array($name)) {
            return $this->defineFuncs($name);
        }
        if (!$name) {
            $this->validationError("Cannot define unnamed function!", Error::DEFINE_FUNC_ERROR, null, '');
        }
        if (is_array($function) && count($function)) {
            //so you can pass array of function names and array of function and pass_sandbox flag
            $pass_sandbox = isset($function[1]) ? $function[1] : false;
            $function = $function[0];
        }
        $original_name = $name;
        $name = $this->normalizeFunc($name);
        if (!is_callable($function)) {
            $this->validationError("Cannot define uncallable function : {$original_name}", Error::DEFINE_FUNC_ERROR, null, $original_name);
        }
        $this->definitions['functions'][$name] = ['function' => $function, 'pass_sandbox' => $pass_sandbox];
        return $this;
    }
PHPSandbox