xref: /PHP-8.2/Zend/tests/gh12102_2.phpt (revision 748adf18)
1--TEST--
2GH-12102: Incorrect "Cannot use temporary expression in write context" error for BP_VAR_FUNC_ARG
3--FILE--
4<?php
5
6function test() {
7    global $ref;
8    byVal(getRef()[0]);
9    var_dump($ref);
10    byRef(getRef()[0]);
11    var_dump($ref);
12}
13
14/* Intentionally declared after test() to avoid compile-time checking of ref args. */
15
16function &getRef() {
17    global $ref;
18    $ref = [];
19    return $ref;
20}
21
22function byVal($arg) {
23    $arg[] = 42;
24}
25
26function byRef(&$arg) {
27    $arg[] = 42;
28}
29
30test();
31
32?>
33--EXPECTF--
34Warning: Undefined array key 0 in %s on line %d
35array(0) {
36}
37array(1) {
38  [0]=>
39  array(1) {
40    [0]=>
41    int(42)
42  }
43}
44