xref: /php-src/Zend/tests/match/027.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() {
19    $i = 0;
20    Test::usesValue(match(true) { true => $i });
21    echo "i is $i\n";
22    $j = 1;
23    Test::usesRef(match(true) { true => $j });
24    echo "j is $j\n";
25}
26main();
27
28?>
29--EXPECTF--
30usesValue 0
31i is 0
32
33Fatal error: Uncaught Error: Test::usesRef(): Argument #1 ($x) could not be passed by reference in %s:%d
34Stack trace:
35#0 %s(%d): main()
36#1 {main}
37  thrown in %s on line %d
38