xref: /PHP-8.1/ext/ffi/tests/trampoline_reset.phpt (revision 4e0bd036)
1--TEST--
2Memory corruption when mixing __callStatic() and FFI
3--EXTENSIONS--
4ffi
5--SKIPIF--
6<?php
7try {
8    $libc = FFI::cdef("int printf(const char *format, ...);", "libc.so.6");
9} catch (Throwable $_) {
10    die('skip libc.so.6 not available');
11}
12?>
13--INI--
14ffi.enable=1
15--FILE--
16<?php
17class Test
18{
19	public static function __callStatic($name, $args)
20	{
21		echo "$name called\n";
22	}
23}
24
25$header = '
26typedef struct _IO_FILE FILE;
27extern FILE *stdout;
28int fprintf(FILE *, const char *, ...);
29int fflush(FILE *);
30';
31$ffi = FFI::cdef($header, 'libc.so.6');
32
33Test::foo();
34Test::bar();
35$ffi->fprintf($ffi->stdout, "FFI\n");
36$ffi->fflush($ffi->stdout);
37Test::baz();
38?>
39--EXPECT--
40foo called
41bar called
42FFI
43baz called
44