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