summaryrefslogtreecommitdiff
path: root/Zend/tests/match/028.phpt
blob: bbc826a73863e01964107acdd59282e17796c642 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
--TEST--
Test result of match cannot be modified by reference
--FILE--
<?php

// opcache can't be certain Test::usesRef is actually this method
if (!class_exists('Test')) {
    class Test {
        public static function usesRef(&$x) {
            $x = 'modified';
        }
        public static function usesValue($x) {
            echo "usesValue $x\n";
        }
    }
}

function main(int $i): int {
    Test::usesValue(match(true) { true => $i });
    Test::usesValue(match($i) { 42 => $i });
    var_dump($i);
    Test::usesRef(match(true) { true => $i });
    var_dump($i);
}

try {
    main(42);
} catch (Error $e) {
    printf("Caught %s\n", $e->getMessage());
}

?>
--EXPECT--
usesValue 42
usesValue 42
int(42)
Caught Cannot pass parameter 1 by reference