xref: /PHP-8.3/Zend/tests/match/028.phpt (revision c322da06)
1--TEST--
2Test result of match cannot be modified by reference
3--FILE--
4<?php
5
6// opcache can't be certain Test::usesRef is actually this method
7if (!class_exists('Test')) {
8    class Test {
9        public static function usesRef(&$x) {
10            $x = 'modified';
11        }
12        public static function usesValue($x) {
13            echo "usesValue $x\n";
14        }
15    }
16}
17
18function main(int $i): int {
19    Test::usesValue(match(true) { true => $i });
20    Test::usesValue(match($i) { 42 => $i });
21    var_dump($i);
22    Test::usesRef(match(true) { true => $i });
23    var_dump($i);
24}
25
26try {
27    main(42);
28} catch (Error $e) {
29    printf("Caught %s\n", $e->getMessage());
30}
31
32?>
33--EXPECT--
34usesValue 42
35usesValue 42
36int(42)
37Caught Test::usesRef(): Argument #1 ($x) could not be passed by reference
38