Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lexer.php/ParserAbstract.php errors when calling namespaced class in php-cli #5985

Open
headbank opened this issue May 5, 2024 · 0 comments
Labels

Comments

@headbank
Copy link

headbank commented May 5, 2024

Describe the bug
If I include/require a class that is namespaced while in drush php-cli, and subsequently call that class, the call fails with this error output:

Undefined array key 265 Lexer.php:168 [warning]
Undefined array key "" ParserAbstract.php:177 [warning]
Undefined array key "" ParserAbstract.php:340 [warning]

The undefined key (265 above) varies depending on the input, for example if I invoke the class with a prepended backslash (absolute namespace) then the key cited is 263.

To Reproduce

  1. Download drush-8.4.12
  2. Create test file Foo.php in D7 document root containing namespaced class declaration (see below)
  3. Execute drush.phar -l <my-site-url> php
  4. In php-cli execute: include getcwd().'/Foo.php';
  5. Execute: echo Bar\Foo::BAR;

Test file contents:

<?php
namespace Bar;

class Foo {
    const BAR = 'baz';
}

Expected behavior
String baz printed on commandline

Actual behavior
Error output as above

Workaround
The equivalent expression(s) do not cause an error when the classname is given indirectly using a string:

>>> echo ('Bar\Foo')::BAR;
baz

System Configuration

Q A
Drush version? 8.4.12
Drupal version? 7.x
PHP version 8.1
OS? Linux

Additional information
I have extracted drush.phar and located the files/lines cited in the errors but this does not make the cause of the issue any clearer to me personally. In general terms, it appears that the command-line parser does not expect to find a backslash in this (perfectly valid in PHP) lexical position.
Calling class_exists('Bar\Foo') does not cause any error, nor does new ReflectionClass('Bar\Foo').

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants