Skip to content

Commit

Permalink
Support static method calls in constant expressions in PHP 7
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Nov 2, 2024
1 parent b8e60b0 commit d732885
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions src/main/php/lang/meta/SyntaxTree.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit d732885

Please sign in to comment.