1--TEST--
2SQLite3::createFunction use F ZPP for trampoline callback and does not leak
3--EXTENSIONS--
4sqlite3
5--FILE--
6<?php
7
8require_once(__DIR__ . '/new_db.inc');
9
10class TrampolineTest {
11    public function __call(string $name, array $arguments) {
12        echo 'Trampoline for ', $name, PHP_EOL;
13        return strtoupper($arguments[0]);
14    }
15}
16$o = new TrampolineTest();
17$callback = [$o, 'strtoupper'];
18
19var_dump($db->createfunction('', $callback));
20
21try {
22    var_dump($db->createfunction(new stdClass(), $callback, new stdClass()));
23} catch (\Throwable $e) {
24    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
25}
26
27try {
28    var_dump($db->createfunction('strtoupper', $callback, new stdClass()));
29} catch (\Throwable $e) {
30    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
31}
32
33echo "Invalid SQLite3 object:\n";
34$rc = new ReflectionClass(SQLite3::class);
35$obj = $rc->newInstanceWithoutConstructor();
36
37try {
38    var_dump($obj->createfunction('strtoupper', $callback));
39} catch (\Throwable $e) {
40    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
41}
42
43var_dump($db->createfunction('strtoupper', $callback));
44
45?>
46--EXPECT--
47bool(false)
48TypeError: SQLite3::createFunction(): Argument #1 ($name) must be of type string, stdClass given
49TypeError: SQLite3::createFunction(): Argument #3 ($argCount) must be of type int, stdClass given
50Invalid SQLite3 object:
51Error: The SQLite3 object has not been correctly initialised or is already closed
52bool(true)
53