PHP.nl

uopz_function

uopz_function

Creates a function at runtime

void **uopz_function** string $function Closure $handler int $modifiers
void **uopz_function** string $class string $function Closure $handler int $modifiers

Creates a function at runtime

classThe name of the class to receive the new function

functionThe name of the function

handlerThe Closure for the function

modifiersThe modifiers for the function, by default copied or ZEND_ACC_PUBLIC

Voorbeeld: example

<?php
uopz_function("my_strlen", function($arg) {
    return strlen($arg);
});
echo my_strlen("Hello World");
?>
11

Voorbeeld: class example

<?php
class My {}

uopz_function(My::class, "strlen", function($arg) {
    return strlen($arg);
}, ZEND_ACC_STATIC);

echo My::strlen("Hello World");
?>
11