|
| 1 | +--TEST-- |
| 2 | +GH-25756 (OPcache: "Invalid opcode 62/4/0" when assigning a reference in a return) |
| 3 | +--EXTENSIONS-- |
| 4 | +opcache |
| 5 | +--INI-- |
| 6 | +opcache.enable=1 |
| 7 | +opcache.enable_cli=1 |
| 8 | +--FILE-- |
| 9 | +<?php |
| 10 | + |
| 11 | +function test_assign_ref() { |
| 12 | + $b = 'success'; |
| 13 | + return $a = &$b; |
| 14 | +} |
| 15 | + |
| 16 | +function &get_ref() { |
| 17 | + static $x = 'from_func'; |
| 18 | + return $x; |
| 19 | +} |
| 20 | + |
| 21 | +function test_assign_func_ref() { |
| 22 | + return $a = &get_ref(); |
| 23 | +} |
| 24 | + |
| 25 | +function test_assign_obj_ref(stdClass $obj, &$b) { |
| 26 | + return $obj->p = &$b; |
| 27 | +} |
| 28 | + |
| 29 | +function test_assign_dim_ref() { |
| 30 | + $b = 'dim_val'; |
| 31 | + $arr = []; |
| 32 | + return $arr[0] = &$b; |
| 33 | +} |
| 34 | + |
| 35 | +class StaticPropHolder { |
| 36 | + public static $p; |
| 37 | +} |
| 38 | + |
| 39 | +function test_assign_static_prop_ref(&$b) { |
| 40 | + return StaticPropHolder::$p = &$b; |
| 41 | +} |
| 42 | + |
| 43 | +function test_list_by_ref() { |
| 44 | + $arr = ['list_val']; |
| 45 | + return [&$a] = $arr; |
| 46 | +} |
| 47 | + |
| 48 | +function test_ternary_assign_ref(bool $cond) { |
| 49 | + $b = 'ternary_val'; |
| 50 | + return $cond ? ($a = &$b) : 'other'; |
| 51 | +} |
| 52 | + |
| 53 | +function test_match_assign_ref(bool $cond) { |
| 54 | + $b = 'match_val'; |
| 55 | + return match ($cond) { |
| 56 | + true => $a = &$b, |
| 57 | + default => 'other', |
| 58 | + }; |
| 59 | +} |
| 60 | + |
| 61 | +function test_typed_assign_ref(): string { |
| 62 | + $b = 'typed_val'; |
| 63 | + return $a = &$b; |
| 64 | +} |
| 65 | + |
| 66 | +$obj = new stdClass(); |
| 67 | +$obj_src = 'obj_prop'; |
| 68 | +$obj_ret = test_assign_obj_ref($obj, $obj_src); |
| 69 | +$obj_src = 'obj_changed'; |
| 70 | + |
| 71 | +$static_src = 'static_prop'; |
| 72 | +$static_ret = test_assign_static_prop_ref($static_src); |
| 73 | +$static_src = 'static_changed'; |
| 74 | + |
| 75 | +$arrow_src = 'arrow_val'; |
| 76 | +$arrow = fn() => $a = &$arrow_src; |
| 77 | + |
| 78 | +echo "1: ", test_assign_ref(), "\n"; |
| 79 | +echo "2: ", test_assign_func_ref(), "\n"; |
| 80 | +echo "3: ", $obj_ret, " / ", $obj->p, "\n"; |
| 81 | +echo "4: ", test_assign_dim_ref(), "\n"; |
| 82 | +echo "5: ", $static_ret, " / ", StaticPropHolder::$p, "\n"; |
| 83 | +echo "6: ", implode(',', test_list_by_ref()), "\n"; |
| 84 | +echo "7: ", test_ternary_assign_ref(true), "\n"; |
| 85 | +echo "8: ", test_match_assign_ref(true), "\n"; |
| 86 | +echo "9: ", test_typed_assign_ref(), "\n"; |
| 87 | +echo "10: ", $arrow(), "\n"; |
| 88 | +?> |
| 89 | +--EXPECT-- |
| 90 | +1: success |
| 91 | +2: from_func |
| 92 | +3: obj_prop / obj_changed |
| 93 | +4: dim_val |
| 94 | +5: static_prop / static_changed |
| 95 | +6: list_val |
| 96 | +7: ternary_val |
| 97 | +8: match_val |
| 98 | +9: typed_val |
| 99 | +10: arrow_val |
0 commit comments