1--TEST-- 2Test basic nullsafe method calls 3--FILE-- 4<?php 5 6class Foo { 7 function null() { 8 var_dump('Foo::null()'); 9 return null; 10 } 11 12 function self() { 13 var_dump('Foo::self()'); 14 return $this; 15 } 16} 17 18var_dump(null?->bar()); 19var_dump(null?->bar(var_dump('Not executed'))); 20var_dump(null?->bar()->baz()); 21var_dump(null?->bar()->baz(var_dump('Not executed'))); 22var_dump(null?->bar()->baz); 23var_dump(null?->bar()::$baz); 24var_dump(null?->bar()::baz()); 25 26$foo = new Foo(); 27var_dump($foo->null()?->bar()); 28var_dump($foo->null()?->bar(var_dump('Not executed'))); 29var_dump($foo->null()?->bar()->baz()); 30var_dump($foo->null()?->bar()->baz(var_dump('Not executed'))); 31var_dump($foo->null()?->bar()->baz); 32var_dump($foo->null()?->bar()::$baz); 33var_dump($foo->null()?->bar()::baz()); 34 35$foo = new Foo(); 36var_dump($foo?->self(var_dump('Executed'))->null()?->bar()); 37var_dump($foo?->self(var_dump('Executed'))->null()?->bar(var_dump('Not executed'))); 38var_dump($foo?->self(var_dump('Executed'))->null()?->bar()->baz()); 39var_dump($foo?->self(var_dump('Executed'))->null()?->bar()->baz(var_dump('Not executed'))); 40var_dump($foo?->self(var_dump('Executed'))->null()?->bar()->baz); 41var_dump($foo?->self(var_dump('Executed'))->null()?->bar()::$baz); 42var_dump($foo?->self(var_dump('Executed'))->null()?->bar()::baz()); 43 44var_dump($foo->self(null?->bar())->null()); 45try { 46 var_dump($foo?->self()[null?->bar()]); 47} catch (Throwable $e) { 48 var_dump($e->getMessage()); 49} 50 51?> 52--EXPECT-- 53NULL 54NULL 55NULL 56NULL 57NULL 58NULL 59NULL 60string(11) "Foo::null()" 61NULL 62string(11) "Foo::null()" 63NULL 64string(11) "Foo::null()" 65NULL 66string(11) "Foo::null()" 67NULL 68string(11) "Foo::null()" 69NULL 70string(11) "Foo::null()" 71NULL 72string(11) "Foo::null()" 73NULL 74string(8) "Executed" 75string(11) "Foo::self()" 76string(11) "Foo::null()" 77NULL 78string(8) "Executed" 79string(11) "Foo::self()" 80string(11) "Foo::null()" 81NULL 82string(8) "Executed" 83string(11) "Foo::self()" 84string(11) "Foo::null()" 85NULL 86string(8) "Executed" 87string(11) "Foo::self()" 88string(11) "Foo::null()" 89NULL 90string(8) "Executed" 91string(11) "Foo::self()" 92string(11) "Foo::null()" 93NULL 94string(8) "Executed" 95string(11) "Foo::self()" 96string(11) "Foo::null()" 97NULL 98string(8) "Executed" 99string(11) "Foo::self()" 100string(11) "Foo::null()" 101NULL 102string(11) "Foo::self()" 103string(11) "Foo::null()" 104NULL 105string(11) "Foo::self()" 106string(38) "Cannot use object of type Foo as array" 107