File tree Expand file tree Collapse file tree 2 files changed +75
-0
lines changed
Zend/tests/nullsafe_operator Expand file tree Collapse file tree 2 files changed +75
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments