From 7e24a444efd3ac2c47043c674699340280ecc5fd Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 4 May 2020 01:03:09 +0200 Subject: [PATCH] File::getMethodProperties(): allow for return type "static" As of PHP 8.0, `static` will be allowed as a return type. Ref: https://wiki.php.net/rfc/static_return_type This commit adjusts the `File::getMethodProperties()` utility method to allow for that. Includes unit test. --- src/Files/File.php | 1 + tests/Core/File/GetMethodPropertiesTest.inc | 7 +++++++ tests/Core/File/GetMethodPropertiesTest.php | 23 +++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/Files/File.php b/src/Files/File.php index 56fd5c1b52..a604ff3eb6 100644 --- a/src/Files/File.php +++ b/src/Files/File.php @@ -1629,6 +1629,7 @@ public function getMethodProperties($stackPtr) T_CALLABLE => T_CALLABLE, T_SELF => T_SELF, T_PARENT => T_PARENT, + T_STATIC => T_STATIC, T_NS_SEPARATOR => T_NS_SEPARATOR, ]; diff --git a/tests/Core/File/GetMethodPropertiesTest.inc b/tests/Core/File/GetMethodPropertiesTest.inc index 7b6223e6bd..b04202fcd2 100644 --- a/tests/Core/File/GetMethodPropertiesTest.inc +++ b/tests/Core/File/GetMethodPropertiesTest.inc @@ -66,3 +66,10 @@ $result = array_map( static fn(int $number) : int => $number + 1, $numbers ); + +class ReturnMe { + /* testReturnTypeStatic */ + private function myFunction(): static { + return $this; + } +} diff --git a/tests/Core/File/GetMethodPropertiesTest.php b/tests/Core/File/GetMethodPropertiesTest.php index b0b2d5e9e2..b801962637 100644 --- a/tests/Core/File/GetMethodPropertiesTest.php +++ b/tests/Core/File/GetMethodPropertiesTest.php @@ -383,6 +383,29 @@ public function testArrowFunction() }//end testArrowFunction() + /** + * Test a function with return type "static". + * + * @return void + */ + public function testReturnTypeStatic() + { + $expected = [ + 'scope' => 'private', + 'scope_specified' => true, + 'return_type' => 'static', + 'nullable_return_type' => false, + 'is_abstract' => false, + 'is_final' => false, + 'is_static' => false, + 'has_body' => true, + ]; + + $this->getMethodPropertiesTestHelper('/* '.__FUNCTION__.' */', $expected); + + }//end testReturnTypeStatic() + + /** * Test helper. *