Skip to content

Commit d732885

Browse files
committed
Support static method calls in constant expressions in PHP 7
1 parent b8e60b0 commit d732885

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ XP Reflection ChangeLog
33

44
## ?.?.? / ????-??-??
55

6+
## 3.3.0 / ????-??-??
7+
8+
* Added support for static method calls in constant expressions in PHP 7.
9+
This allows using first-class callables as annotation arguments.
10+
(@thekid)
11+
612
## 3.2.0 / 2024-08-26
713

814
* Merged PR #43: Add support for asymmetric visibility for properties, see

src/main/php/lang/meta/SyntaxTree.class.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use ReflectionClass;
44
use lang\IllegalAccessException;
5-
use lang\ast\nodes\{Literal, Variable};
5+
use lang\ast\nodes\{Literal, Variable, InvokeExpression};
66
use lang\ast\{Visitor, Type};
77

88
class SyntaxTree extends Visitor {
@@ -102,8 +102,14 @@ public function scope($self) {
102102
? substr($c, 1)
103103
: (new ReflectionClass($c))->getConstant($self->member->expression)
104104
;
105+
} else if ($self->member instanceof InvokeExpression) {
106+
$arguments= [];
107+
foreach ($self->member->arguments as $key => $node) {
108+
$arguments[$key]= $node->visit($this);
109+
}
110+
return (new ReflectionClass($c))->getMethod($self->member->expression)->invokeArgs(null, $arguments);
105111
} else {
106-
throw new IllegalAccessException('Cannot resolve '.$type->name.'::'.$self->member->kind);
112+
throw new IllegalAccessException('Cannot resolve '.$c.'::'.$self->member->kind);
107113
}
108114
}
109115

0 commit comments

Comments
 (0)