Skip to content

Commit

Permalink
Reflection: fixed parseUseStatements for PHP 8 [Closes #229]
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes authored and dg committed Jul 30, 2020
1 parent 4d493d3 commit b6414bc
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Utils/Reflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,15 @@ private static function parseUseStatements(string $code, string $forClass = null
$namespace = $class = $classLevel = $level = null;
$res = $uses = [];

$nameTokens = PHP_VERSION_ID < 80000
? [T_STRING, T_NS_SEPARATOR]
: [T_STRING, T_NAME_QUALIFIED, T_NAME_FULLY_QUALIFIED];

while ($token = current($tokens)) {
next($tokens);
switch (is_array($token) ? $token[0] : $token) {
case T_NAMESPACE:
$namespace = ltrim(self::fetch($tokens, [T_STRING, T_NS_SEPARATOR]) . '\\', '\\');
$namespace = ltrim(self::fetch($tokens, $nameTokens) . '\\', '\\');
$uses = [];
break;

Expand All @@ -277,10 +281,10 @@ private static function parseUseStatements(string $code, string $forClass = null
break;

case T_USE:
while (!$class && ($name = self::fetch($tokens, [T_STRING, T_NS_SEPARATOR]))) {
while (!$class && ($name = self::fetch($tokens, $nameTokens))) {
$name = ltrim($name, '\\');
if (self::fetch($tokens, '{')) {
while ($suffix = self::fetch($tokens, [T_STRING, T_NS_SEPARATOR])) {
while ($suffix = self::fetch($tokens, $nameTokens)) {
if (self::fetch($tokens, T_AS)) {
$uses[self::fetch($tokens, T_STRING)] = $name . $suffix;
} else {
Expand Down

0 comments on commit b6414bc

Please sign in to comment.