Skip to content

Commit

Permalink
Remove PHP 7.0 specific handling
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Mar 23, 2024
1 parent b3f7473 commit c48c309
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
12 changes: 5 additions & 7 deletions src/main/php/lang/meta/SyntaxTree.class.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace lang\meta;

use ReflectionClass;
use lang\IllegalAccessException;
use lang\ast\nodes\{Literal, Variable};
use lang\ast\{Visitor, Type};
Expand Down Expand Up @@ -76,7 +77,7 @@ public function array($self) {
* @return var
*/
public function new($self) {
$c= new \ReflectionClass($this->resolve($self->type));
$c= new ReflectionClass($this->resolve($self->type));
$arguments= [];
foreach ($self->arguments as $key => $node) {
$arguments[$key]= $node->visit($this);
Expand All @@ -93,16 +94,13 @@ public function new($self) {
public function scope($self) {
$c= $this->resolve($self->type);

// Use PHP reflection API to access members' runtime values. We cannot use
// getStaticPropertyValue() as it cannot get non-public members in PHP 7.0
// Use PHP reflection API to access members' runtime values
if ($self->member instanceof Variable) {
$p= (new \ReflectionClass($c))->getProperty($self->member->pointer ?? $self->member->name);
$p->setAccessible(true);
return $p->getValue();
return (new ReflectionClass($c))->getStaticPropertyValue($self->member->pointer ?? $self->member->name);
} else if ($self->member instanceof Literal) {
return 'class' === $self->member->expression
? substr($c, 1)
: (new \ReflectionClass($c))->getConstant($self->member->expression)
: (new ReflectionClass($c))->getConstant($self->member->expression)
;
} else {
throw new IllegalAccessException('Cannot resolve '.$type->name.'::'.$self->member->kind);
Expand Down
6 changes: 1 addition & 5 deletions src/main/php/lang/reflection/Type.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,8 @@ public function constants() { return new Constants($this->reflect); }

/** @return ?lang.reflection.Constant */
public function constant($name) {

// Cannot use getReflectionConstant(), which does not exist in PHP 7.0.
// Instantiate the polyfilled ReflectionClassConstant class directly in
// order to make this compatible will all versions.
return $this->reflect->hasConstant($name)
? new Constant(new \ReflectionClassConstant($this->reflect->name, $name))
? new Constant($this->reflect->getReflectionConstant($name))
: null
;
}
Expand Down

0 comments on commit c48c309

Please sign in to comment.