Skip to content

Commit 7e24a44

Browse files
committed
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.
1 parent ce62dee commit 7e24a44

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/Files/File.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,7 @@ public function getMethodProperties($stackPtr)
16291629
T_CALLABLE => T_CALLABLE,
16301630
T_SELF => T_SELF,
16311631
T_PARENT => T_PARENT,
1632+
T_STATIC => T_STATIC,
16321633
T_NS_SEPARATOR => T_NS_SEPARATOR,
16331634
];
16341635

tests/Core/File/GetMethodPropertiesTest.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,10 @@ $result = array_map(
6666
static fn(int $number) : int => $number + 1,
6767
$numbers
6868
);
69+
70+
class ReturnMe {
71+
/* testReturnTypeStatic */
72+
private function myFunction(): static {
73+
return $this;
74+
}
75+
}

tests/Core/File/GetMethodPropertiesTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,29 @@ public function testArrowFunction()
383383
}//end testArrowFunction()
384384

385385

386+
/**
387+
* Test a function with return type "static".
388+
*
389+
* @return void
390+
*/
391+
public function testReturnTypeStatic()
392+
{
393+
$expected = [
394+
'scope' => 'private',
395+
'scope_specified' => true,
396+
'return_type' => 'static',
397+
'nullable_return_type' => false,
398+
'is_abstract' => false,
399+
'is_final' => false,
400+
'is_static' => false,
401+
'has_body' => true,
402+
];
403+
404+
$this->getMethodPropertiesTestHelper('/* '.__FUNCTION__.' */', $expected);
405+
406+
}//end testReturnTypeStatic()
407+
408+
386409
/**
387410
* Test helper.
388411
*

0 commit comments

Comments
 (0)