php-scoper icon indicating copy to clipboard operation
php-scoper copied to clipboard

PHP 8.0 "attribute" use statement incorrectly prefixed or breaks prefixing entirely

Open moorscode opened this issue 2 years ago • 0 comments

Bug report

Question Answer
PHP-Scoper version 0.15.0
PHP version all
Platform with version all

Prefixing of PHP 8.0+ attributes is not behaving consistently.

When using a single line attribute, which is imported using a use statement, the class in the use statement is being prefixed.

However, when using the fully qualified classname in the inline attribute call ~or using a multiline attribute notation~ the build files are created with expected prefixes (the incorrect prefix is not being added).

Correction on the assumption that multiline attributes were giving the desired results. Whenever an attribute is defined over multiple lines, the "source" file is being placed in the build directory without any errors or warnings, but also without any prefixes.

I've added a "neutral" use SomethingElse; to the source files to validate that prefixing happens, though this statement is not being prefixed in the multiline-*.php files in the build results.

Steps to reproduce:

  1. Clone the main branch of the php-scoper-attributes-prefixed-poc repository
  2. Run composer install
  3. Run php ./vendor/humbug/php-scoper/bin/php-scoper add-prefix
  4. Inspect the files in the build directory and see use TestPrefix\ReturnTypeWillChange; instead of the use ReturnTypeWillChange; statement in the inline-with-use.php file

moorscode avatar Oct 28 '21 15:10 moorscode