mirror of
https://github.com/php/php-src.git
synced 2026-04-29 19:23:22 +02:00
db991bc0f1
This works similar to `dlsym(RTLD_DEFAULT, …)` with the caveat that symbols on Windows may not be unique, and are usually qualified by the module they are exported from. That means that wrong symbols may be fetched, potentially causing serious issues; therefore this usage is not recommended for production purposes, but is a nice simplification for quick experiments and the ext/ffi test suite. Closes GH-16351.
46 lines
849 B
PHP
46 lines
849 B
PHP
--TEST--
|
|
FFI 200: PHP callbacks
|
|
--EXTENSIONS--
|
|
ffi
|
|
--SKIPIF--
|
|
<?php require_once('utils.inc'); ?>
|
|
<?php
|
|
try {
|
|
FFI::cdef("void* zend_write;");
|
|
} catch (Throwable $e) {
|
|
die('skip PHP symbols not available');
|
|
}
|
|
?>
|
|
--INI--
|
|
ffi.enable=1
|
|
opcache.jit=0
|
|
--FILE--
|
|
<?php
|
|
require_once('utils.inc');
|
|
$zend = FFI::cdef("
|
|
typedef size_t (*zend_write_func_t)(const char *str, size_t str_length);
|
|
extern zend_write_func_t zend_write;
|
|
");
|
|
|
|
echo "Hello World!\n";
|
|
|
|
$orig_zend_write = clone $zend->zend_write;
|
|
$zend->zend_write = function($str, $len) {
|
|
global $orig_zend_write;
|
|
$orig_zend_write("{\n\t", 3);
|
|
$ret = $orig_zend_write($str, $len);
|
|
$orig_zend_write("}\n", 2);
|
|
return $ret;
|
|
};
|
|
echo "Hello World!\n";
|
|
$zend->zend_write = $orig_zend_write;
|
|
|
|
echo "Hello World!\n";
|
|
?>
|
|
--EXPECT--
|
|
Hello World!
|
|
{
|
|
Hello World!
|
|
}
|
|
Hello World!
|