Skip to content

PHP 8 new with arbitrary expressions leads to a syntax issue #952

@Geolim4

Description

@Geolim4
  • PHPMD version: 2.12.0
  • PHP Version: 8.0.2
  • Installation type: composer
  • Operating System / Distribution & Version: Not relevant

Current Behavior

This (valid) code:

$myObject = new (SomeArbitraryCode::class . 'loremIpsum' . trim(' Hello '))($arg1, $arg2);

Leads to the following error:

Unexpected token: (, line: xx, col: xx, file: xxxxxxxxxxx.php.
#0 xxxxxxxxxxx\vendor\pdepend\pdepend\src\main\php\PDepend\Source\Language\PHP\AbstractPHPParser.php(7844): PDepend\Source\Parser\UnexpectedTokenException->__construct(Object(PDepend\Source\Tokenizer\Token), Object(PDepend\Source\AST\ASTCompilationUnit)
)

Expected Behavior

No error, dynamic class instantiation has been introduced as of PHP 8:
https://www.php.net/manual/en/language.oop5.basic.php

Steps To Reproduce:

Just analyses the piece of code above.

Checks before submitting

  • Be sure that there isn't already an issue about this. See: Issues list
  • Be sure that there isn't already a pull request about this. See: Pull requests
  • I have added every step to reproduce the bug.
  • If possible I added relevant code examples.
  • This issue is about 1 bug and nothing more.
  • The issue has a descriptive title. For example: "JSON rendering failed on Windows for filenames with space".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions