xref: /PHP-8.3/ext/opcache/tests/jit/count_001.phpt (revision e9f783fc)
1--TEST--
2JIT COUNT: 001
3--INI--
4opcache.enable=1
5opcache.enable_cli=1
6opcache.file_update_protection=0
7opcache.jit_buffer_size=1M
8;opcache.jit_debug=1
9--EXTENSIONS--
10opcache
11--FILE--
12<?php
13class ThrowsInDestructor {
14    public function __destruct() {
15        throw new RuntimeException("In destructor");
16    }
17}
18class C {
19    public static function create_array(int $i): array {
20        return array_fill(0, $i, new stdClass());
21    }
22
23    public static function foo() {
24        $x = [self::create_array(5)];
25        echo count(self::create_array(0)), "\n";
26        echo count(self::create_array(1)), "\n";
27        echo count($x[0]), "\n";
28        $a = [];
29        for ($i = 0; $i < 4; $i++) {
30            $a[] = $i;
31            echo count($a) . "\n";
32        }
33    }
34    public static function count_ref(array &$ref): int {
35        return count($ref);
36    }
37
38    public static function count_throws(): int {
39        $result = count([new ThrowsInDestructor()]);
40        echo "Unreachable\n";
41        return $result;
42    }
43}
44C::foo();
45$x = ['x', 'y', 'z', 'a', new stdClass()];
46echo C::count_ref($x), "\n";
47for ($i = 0; $i < 5; $i++) {
48    try {
49        echo C::count_throws(), "\n";
50    } catch (RuntimeException $e) {
51        printf("Caught %s\n", $e->getMessage());
52    }
53}
54
55--EXPECT--
560
571
585
591
602
613
624
635
64Caught In destructor
65Caught In destructor
66Caught In destructor
67Caught In destructor
68Caught In destructor