xref: /PHP-8.3/ext/ffi/tests/200.phpt (revision bd9f4fa6)
1--TEST--
2FFI 200: PHP callbacks
3--EXTENSIONS--
4ffi
5--SKIPIF--
6<?php require_once('utils.inc'); ?>
7<?php
8try {
9    FFI::cdef("void* zend_write;", ffi_get_php_dll_name());
10} catch (Throwable $e) {
11    die('skip PHP symbols not available');
12}
13?>
14--INI--
15ffi.enable=1
16opcache.jit=0
17--FILE--
18<?php
19require_once('utils.inc');
20$zend = FFI::cdef("
21    typedef size_t (*zend_write_func_t)(const char *str, size_t str_length);
22    extern zend_write_func_t zend_write;
23", ffi_get_php_dll_name());
24
25echo "Hello World!\n";
26
27$orig_zend_write = clone $zend->zend_write;
28$zend->zend_write = function($str, $len) {
29    global $orig_zend_write;
30    $orig_zend_write("{\n\t", 3);
31    $ret = $orig_zend_write($str, $len);
32    $orig_zend_write("}\n", 2);
33    return $ret;
34};
35echo "Hello World!\n";
36$zend->zend_write = $orig_zend_write;
37
38echo "Hello World!\n";
39?>
40--EXPECT--
41Hello World!
42{
43	Hello World!
44}
45Hello World!
46