PHP 7.4.8 Released!

PHP Callbacks

It is possible to assign a PHP closure to a native variable of function pointer type or to pass it as a function argument:

    typedef int (*zend_write_func_t)(const char *str, size_t str_length);
    extern zend_write_func_t zend_write;
"Hello World 1!\n";
$orig_zend_write = clone $zend->zend_write;
$zend->zend_write = function($str$len) {
$ret $orig_zend_write($str$len);
"Hello World 2!\n";
$zend->zend_write $orig_zend_write;
"Hello World 3!\n";

El resultado del ejemplo serĂ­a:

Hello World 1!
        Hello World 2!
Hello World 3!
Although this works, this functionality is not supported on all libffi platforms, is not efficient and leaks resources by the end of request.

It is therefore recommended to minimize the usage of PHP callbacks.

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top