From 3472e69b2c7df2c1aa46efc3b415ff03978dce2a Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Mon, 27 Sep 2021 15:53:49 +0100 Subject: [PATCH 1/2] Adds failing test --- tests/ReflectionClosurePhp80Test.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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, ) { }; From 788c2b9afef366bc465a0fcf04fb719fadf4d546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Lundb=C3=B8l?= Date: Tue, 28 Sep 2021 23:26:43 +0200 Subject: [PATCH 2/2] Fix failing test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michael Lundbøl Use minus number instead Signed-off-by: Michael Lundbøl --- src/Support/ReflectionClosure.php | 2 ++ 1 file changed, 2 insertions(+) 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';