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 strnatcmp(...$arguments);
14    }
15}
16$o = new TrampolineTest();
17$callback = [$o, 'NAT'];
18
19var_dump($db->createCollation('', $callback));
20
21try {
22    var_dump($db->createCollation(new stdClass(), $callback));
23} catch (\Throwable $e) {
24    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
25}
26try {
27    var_dump($db->createCollation('NAT', $callback, new stdClass()));
28} catch (\Throwable $e) {
29    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
30}
31
32echo "Invalid SQLite3 object:\n";
33$rc = new ReflectionClass(SQLite3::class);
34$obj = $rc->newInstanceWithoutConstructor();
35
36try {
37    var_dump($obj->createCollation('NAT', $callback));
38} catch (\Throwable $e) {
39    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
40}
41
42var_dump($db->createCollation('NAT', $callback));
43
44?>
45--EXPECT--
46bool(false)
47TypeError: SQLite3::createCollation(): Argument #1 ($name) must be of type string, stdClass given
48ArgumentCountError: SQLite3::createCollation() expects exactly 2 arguments, 3 given
49Invalid SQLite3 object:
50Error: The SQLite3 object has not been correctly initialised or is already closed
51bool(true)
52