| 1 |
<?php |
| 2 |
|
| 3 |
namespace WP_DEFENDER_VENDOR\Safe; |
| 4 |
|
| 5 |
use WP_DEFENDER_VENDOR\Safe\Exceptions\FunchandException; |
| 6 |
|
| 7 |
/** |
| 8 |
* Creates an anonymous function from the parameters passed, and |
| 9 |
* returns a unique name for it. |
| 10 |
* |
| 11 |
* @param string $args The function arguments. |
| 12 |
* @param string $code The function code. |
| 13 |
* @return string Returns a unique function name as a string. |
| 14 |
* @throws FunchandException |
| 15 |
* |
| 16 |
*/ |
| 17 |
function create_function(string $args, string $code): string |
| 18 |
{ |
| 19 |
error_clear_last(); |
| 20 |
$result = \create_function($args, $code); |
| 21 |
if ($result === false) { |
| 22 |
throw FunchandException::createFromPhpError(); |
| 23 |
} |
| 24 |
return $result; |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
/** |
| 29 |
* |
| 30 |
* |
| 31 |
* @param callable(): void $function The function to register. |
| 32 |
* @param mixed $params |
| 33 |
* @throws FunchandException |
| 34 |
* |
| 35 |
*/ |
| 36 |
function register_tick_function(callable $function, ...$params): void |
| 37 |
{ |
| 38 |
error_clear_last(); |
| 39 |
if ($params !== []) { |
| 40 |
$result = \register_tick_function($function, ...$params); |
| 41 |
} else { |
| 42 |
$result = \register_tick_function($function); |
| 43 |
} |
| 44 |
if ($result === false) { |
| 45 |
throw FunchandException::createFromPhpError(); |
| 46 |
} |
| 47 |
} |
| 48 |
|