1--TEST-- 2Test nullsafe operator in encaps vars 3--FILE-- 4<?php 5 6class Foo { 7 public $bar = 'bar'; 8 9 function qux() { 10 return 'qux'; 11 } 12} 13 14$null = null; 15$foo = new Foo(); 16 17var_dump("{$null?->foo}"); 18var_dump("{$null?->bar()}"); 19var_dump("$null?->foo"); 20var_dump("$null?->bar()"); 21 22var_dump("{$foo?->bar}"); 23var_dump("{$foo?->baz}"); 24var_dump("{$foo?->qux()}"); 25try { 26 var_dump("{$foo?->quux()}"); 27} catch (Throwable $e) { 28 var_dump($e->getMessage()); 29} 30 31var_dump("$foo?->bar"); 32var_dump("$foo?->baz"); 33var_dump("$foo?->qux()"); 34try { 35 var_dump("$foo?->quux()"); 36} catch (Throwable $e) { 37 var_dump($e->getMessage()); 38} 39 40?> 41--EXPECTF-- 42string(0) "" 43string(0) "" 44string(0) "" 45string(2) "()" 46string(3) "bar" 47 48Warning: Undefined property: Foo::$baz in %s.php on line 20 49string(0) "" 50string(3) "qux" 51string(36) "Call to undefined method Foo::quux()" 52string(3) "bar" 53 54Warning: Undefined property: Foo::$baz in %s.php on line 29 55string(0) "" 56 57Warning: Undefined property: Foo::$qux in %s.php on line 30 58string(2) "()" 59 60Warning: Undefined property: Foo::$quux in %s.php on line 32 61string(2) "()" 62