diff --git a/src/Support/ReflectionClosure.php b/src/Support/ReflectionClosure.php index 139696d3..9d5a6ee4 100644 --- a/src/Support/ReflectionClosure.php +++ b/src/Support/ReflectionClosure.php @@ -5,6 +5,7 @@ defined('T_NAME_QUALIFIED') || define('T_NAME_QUALIFIED', -4); defined('T_NAME_FULLY_QUALIFIED') || define('T_NAME_FULLY_QUALIFIED', -5); defined('T_FN') || define('T_FN', -6); +defined('T_NULLSAFE_OBJECT_OPERATOR') || define('T_NULLSAFE_OBJECT_OPERATOR', -7); use Closure; use ReflectionFunction; @@ -389,6 +390,7 @@ public function getCode() $lastState = 'closure'; break; case T_OBJECT_OPERATOR: + case T_NULLSAFE_OBJECT_OPERATOR: case T_DOUBLE_COLON: $code .= $token[1]; $lastState = 'closure'; diff --git a/tests/ReflectionClosurePhp80Test.php b/tests/ReflectionClosurePhp80Test.php index a9b15e10..522b14b3 100644 --- a/tests/ReflectionClosurePhp80Test.php +++ b/tests/ReflectionClosurePhp80Test.php @@ -37,7 +37,7 @@ expect($f1)->toBeCode($e1); }); -test('null safe operator', function () { +test('null safe operator with methods', function () { $f1 = function () { $obj = new \stdClass(); @@ -52,6 +52,21 @@ expect($f1)->toBeCode($e1); }); +test('null safe operator with properties', function () { + $f1 = function () { + $obj = new \stdClass(); + + return $obj?->invalid; + }; + $e1 = 'function () { + $obj = new \stdClass(); + + return $obj?->invalid; + }'; + + expect($f1)->toBeCode($e1); +}); + test('trailling comma', function () { $f1 = function (string $param, ) { };