Skip to content

Commit 00dad58

Browse files
committed
Add nullsafe as reference tests
1 parent 4f6999c commit 00dad58

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

Zend/tests/nullsafe_operator/016.phpt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
Test nullsafe in function argument
3+
--FILE--
4+
<?php
5+
6+
class Foo {
7+
public $bar;
8+
}
9+
10+
function set(&$ref, $value) {
11+
$ref = $value;
12+
}
13+
14+
function test($foo) {
15+
set($foo?->bar, 'bar');
16+
var_dump($foo);
17+
(strrev('tes'))($foo?->bar, 'bar2');
18+
var_dump($foo);
19+
}
20+
21+
test(null);
22+
test(new Foo());
23+
24+
?>
25+
--EXPECT--
26+
NULL
27+
NULL
28+
object(Foo)#1 (1) {
29+
["bar"]=>
30+
string(3) "bar"
31+
}
32+
object(Foo)#1 (1) {
33+
["bar"]=>
34+
string(4) "bar2"
35+
}

Zend/tests/nullsafe_operator/017.phpt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
Test return nullsafe as ref
3+
--FILE--
4+
<?php
5+
6+
class Foo {
7+
public $bar;
8+
}
9+
10+
function &get_bar_ref($foo) {
11+
return $foo?->bar;
12+
}
13+
14+
function test($foo) {
15+
$barRef = &get_bar_ref($foo);
16+
$barRef = 'bar';
17+
unset($barRef);
18+
var_dump($foo);
19+
20+
$barRef = &(strrev('fer_rab_teg'))($foo);
21+
$barRef = 'bar2';
22+
unset($barRef);
23+
var_dump($foo);
24+
}
25+
26+
test(null);
27+
test(new Foo());
28+
29+
?>
30+
--EXPECT--
31+
NULL
32+
NULL
33+
object(Foo)#1 (1) {
34+
["bar"]=>
35+
string(3) "bar"
36+
}
37+
object(Foo)#1 (1) {
38+
["bar"]=>
39+
string(4) "bar2"
40+
}

0 commit comments

Comments
 (0)