diff --git a/ChangeLog.md b/ChangeLog.md index d599075..77488cc 100755 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -3,6 +3,12 @@ XP Reflection ChangeLog ## ?.?.? / ????-??-?? +## 3.3.0 / ????-??-?? + +* Added support for static method calls in constant expressions in PHP 7. + This allows using first-class callables as annotation arguments. + (@thekid) + ## 3.2.0 / 2024-08-26 * Merged PR #43: Add support for asymmetric visibility for properties, see diff --git a/src/main/php/lang/meta/SyntaxTree.class.php b/src/main/php/lang/meta/SyntaxTree.class.php index 0f25656..4fd137d 100755 --- a/src/main/php/lang/meta/SyntaxTree.class.php +++ b/src/main/php/lang/meta/SyntaxTree.class.php @@ -2,7 +2,7 @@ use ReflectionClass; use lang\IllegalAccessException; -use lang\ast\nodes\{Literal, Variable}; +use lang\ast\nodes\{Literal, Variable, InvokeExpression}; use lang\ast\{Visitor, Type}; class SyntaxTree extends Visitor { @@ -102,8 +102,14 @@ public function scope($self) { ? substr($c, 1) : (new ReflectionClass($c))->getConstant($self->member->expression) ; + } else if ($self->member instanceof InvokeExpression) { + $arguments= []; + foreach ($self->member->arguments as $key => $node) { + $arguments[$key]= $node->visit($this); + } + return (new ReflectionClass($c))->getMethod($self->member->expression)->invokeArgs(null, $arguments); } else { - throw new IllegalAccessException('Cannot resolve '.$type->name.'::'.$self->member->kind); + throw new IllegalAccessException('Cannot resolve '.$c.'::'.$self->member->kind); } }