theseer / Autoload

A lightweight php namespace aware autoload generator and phar archive builder
Other
388 stars 47 forks source link

Parser does not handle (class) constants named `NAMESPACE` #115

Closed sebastianbergmann closed 1 month ago

sebastianbergmann commented 1 month ago

I wanted to build the PHAR for PHPUnit 11.4.0 just now and ran into this issue:

❯ ant signed-phar
Buildfile: /usr/local/src/phpunit/build.xml

clean-build-artifacts:

clean-vendor:
   [delete] Deleting directory /usr/local/src/phpunit/vendor

clean:

install-dependencies:
 [composer] Installing dependencies from lock file (including require-dev)
 [composer] Verifying lock file contents can be installed on current platform.
 [composer] Package operations: 25 installs, 0 updates, 0 removals
 [composer]   - Installing myclabs/deep-copy (1.12.0): Extracting archive
 [composer]   - Installing phar-io/version (3.2.1): Extracting archive
 [composer]   - Installing phar-io/manifest (2.0.4): Extracting archive
 [composer]   - Installing theseer/tokenizer (1.2.3): Extracting archive
 [composer]   - Installing sebastian/version (5.0.1): Extracting archive
 [composer]   - Installing nikic/php-parser (v5.3.0): Extracting archive
 [composer]   - Installing sebastian/lines-of-code (3.0.1): Extracting archive
 [composer]   - Installing sebastian/environment (7.2.0): Extracting archive
 [composer]   - Installing sebastian/complexity (4.0.1): Extracting archive
 [composer]   - Installing sebastian/code-unit-reverse-lookup (4.0.1): Extracting archive
 [composer]   - Installing phpunit/php-text-template (4.0.1): Extracting archive
 [composer]   - Installing phpunit/php-file-iterator (5.1.0): Extracting archive
 [composer]   - Installing phpunit/php-code-coverage (11.0.6): Extracting archive
 [composer]   - Installing phpunit/php-invoker (5.0.1): Extracting archive
 [composer]   - Installing phpunit/php-timer (7.0.1): Extracting archive
 [composer]   - Installing sebastian/cli-parser (3.0.2): Extracting archive
 [composer]   - Installing sebastian/code-unit (3.0.1): Extracting archive
 [composer]   - Installing sebastian/recursion-context (6.0.2): Extracting archive
 [composer]   - Installing sebastian/exporter (6.1.3): Extracting archive
 [composer]   - Installing sebastian/diff (6.0.2): Extracting archive
 [composer]   - Installing sebastian/comparator (6.1.0): Extracting archive
 [composer]   - Installing sebastian/object-reflector (4.0.1): Extracting archive
 [composer]   - Installing sebastian/global-state (7.0.2): Extracting archive
 [composer]   - Installing sebastian/object-enumerator (6.0.1): Extracting archive
 [composer]   - Installing sebastian/type (5.1.0): Extracting archive
 [composer] Generating optimized autoload files
 [composer] 23 packages you are using are looking for funding.
 [composer] Use the `composer fund` command to find out more!

-phar-prepare:
    [mkdir] Created dir: /usr/local/src/phpunit/build/artifacts
    [mkdir] Created dir: /usr/local/src/phpunit/build/tmp/phar
    [mkdir] Created dir: /usr/local/src/phpunit/build/tmp/phar-scoped
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar
     [copy] Copying 17 files to /usr/local/src/phpunit/build/tmp/phar/schema
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/php-code-coverage
     [copy] Copying 112 files to /usr/local/src/phpunit/build/tmp/phar/php-code-coverage
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/php-file-iterator
     [copy] Copying 4 files to /usr/local/src/phpunit/build/tmp/phar/php-file-iterator
     [copy] Copying 4 files to /usr/local/src/phpunit/build/tmp/phar/php-invoker
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/php-text-template
     [copy] Copying 4 files to /usr/local/src/phpunit/build/tmp/phar/php-text-template
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/php-timer
     [copy] Copying 6 files to /usr/local/src/phpunit/build/tmp/phar/php-timer
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/sebastian-cli-parser
     [copy] Copying 6 files to /usr/local/src/phpunit/build/tmp/phar/sebastian-cli-parser
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/sebastian-code-unit
     [copy] Copying 16 files to /usr/local/src/phpunit/build/tmp/phar/sebastian-code-unit
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/sebastian-code-unit-reverse-lookup
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/sebastian-code-unit-reverse-lookup
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/sebastian-comparator
     [copy] Copying 17 files to /usr/local/src/phpunit/build/tmp/phar/sebastian-comparator
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/sebastian-complexity
     [copy] Copying 8 files to /usr/local/src/phpunit/build/tmp/phar/sebastian-complexity
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/sebastian-diff
     [copy] Copying 16 files to /usr/local/src/phpunit/build/tmp/phar/sebastian-diff
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/sebastian-environment
     [copy] Copying 2 files to /usr/local/src/phpunit/build/tmp/phar/sebastian-environment
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/sebastian-exporter
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/sebastian-exporter
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/sebastian-global-state
     [copy] Copying 6 files to /usr/local/src/phpunit/build/tmp/phar/sebastian-global-state
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/sebastian-lines-of-code
     [copy] Copying 7 files to /usr/local/src/phpunit/build/tmp/phar/sebastian-lines-of-code
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/object-enumerator
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/sebastian-object-enumerator
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/object-reflector
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/sebastian-object-reflector
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/sebastian-recursion-context
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/sebastian-recursion-context
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/sebastian-type
     [copy] Copying 21 files to /usr/local/src/phpunit/build/tmp/phar/sebastian-type
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/sebastian-version
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/sebastian-version
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/myclabs-deep-copy
     [copy] Copying 26 files to /usr/local/src/phpunit/build/tmp/phar/myclabs-deep-copy
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/nikic-php-parser
     [copy] Copying 265 files to /usr/local/src/phpunit/build/tmp/phar/nikic-php-parser
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/phar-io-manifest
     [copy] Copying 51 files to /usr/local/src/phpunit/build/tmp/phar/phar-io-manifest
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/phar-io-version
     [copy] Copying 21 files to /usr/local/src/phpunit/build/tmp/phar/phar-io-version
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp/phar/theseer-tokenizer
     [copy] Copying 8 files to /usr/local/src/phpunit/build/tmp/phar/theseer-tokenizer

-phar-determine-version:

phar:

-phar-determine-version:

-phar-build:
     [copy] Copying 927 files to /usr/local/src/phpunit/build/tmp/phar/phpunit
[php-scoper] 
[php-scoper] 
[php-scoper]     ____  __  ______     _____
[php-scoper]    / __ \/ / / / __ \   / ___/_________  ____  ___  _____
[php-scoper]   / /_/ / /_/ / /_/ /   \__ \/ ___/ __ \/ __ \/ _ \/ ___/
[php-scoper]  / ____/ __  / ____/   ___/ / /__/ /_/ / /_/ /  __/ /
[php-scoper] /_/   /_/ /_/_/       /____/\___/\____/ .___/\___/_/
[php-scoper]                                      /_/
[php-scoper] 
[php-scoper] PhpScoper version 0.18.15 2024-09-02 13:37:20 UTC
[php-scoper] 
[php-scoper]     0/1578 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░]   0%
[php-scoper]   158/1578 [▓▓░░░░░░░░░░░░░░░░░░░░░░░░░░]  10%
[php-scoper]   286/1578 [▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░░░░]  18%
[php-scoper]   293/1578 [▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░░░░]  18%
[php-scoper]   316/1578 [▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░░░░]  20%
[php-scoper]   474/1578 [▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░]  30%
[php-scoper]   632/1578 [▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░]  40%
[php-scoper]   789/1578 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░]  50%
[php-scoper]   947/1578 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░]  60%
[php-scoper]  1105/1578 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░]  70%
[php-scoper]  1263/1578 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░]  80%
[php-scoper]  1421/1578 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░]  90%
[php-scoper] 
[php-scoper] 
[php-scoper]  [OK] Successfully prefixed 1578 files.                                         
[php-scoper] 
[php-scoper]  // Memory usage: 23.26MB (peak: 61.92MB), time: 7.86s                          
[php-scoper] 
[php-scoper]  1578/1578 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
    [phpab] phpab 1.29.1 - Copyright (C) 2009 - 2024 by Arne Blankerts and Contributors
    [phpab] 
    [phpab] Scanning directory /usr/local/src/phpunit/build/tmp/phar-scoped
    [phpab] PHP Warning:  Undefined array key 1 in phar:///usr/local/src/phpunit/tools/phpab/phpab/Parser.php on line 425
    [phpab] PHP Warning:  Undefined array key 1 in phar:///usr/local/src/phpunit/tools/phpab/phpab/Parser.php on line 425
    [phpab] PHP Warning:  Undefined array key 1 in phar:///usr/local/src/phpunit/tools/phpab/phpab/Parser.php on line 425
    [phpab] PHP Warning:  Undefined array key 1 in phar:///usr/local/src/phpunit/tools/phpab/phpab/Parser.php on line 425
    [phpab] PHP Warning:  Undefined array key 1 in phar:///usr/local/src/phpunit/tools/phpab/phpab/Parser.php on line 425
    [phpab] PHP Warning:  Undefined array key 1 in phar:///usr/local/src/phpunit/tools/phpab/phpab/Parser.php on line 425
    [phpab] PHP Warning:  Undefined array key 1 in phar:///usr/local/src/phpunit/tools/phpab/phpab/Parser.php on line 425
    [phpab] PHP Warning:  Undefined array key 1 in phar:///usr/local/src/phpunit/tools/phpab/phpab/Parser.php on line 425
    [phpab] PHP Warning:  Undefined array key 1 in phar:///usr/local/src/phpunit/tools/phpab/phpab/Parser.php on line 425
    [phpab] PHP Warning:  Undefined array key 1 in phar:///usr/local/src/phpunit/tools/phpab/phpab/Parser.php on line 425
    [phpab] PHP Warning:  Undefined array key 1 in phar:///usr/local/src/phpunit/tools/phpab/phpab/Parser.php on line 425
    [phpab] 
    [phpab] phar archive '/usr/local/src/phpunit/build/artifacts/phpunit-library-11.4.0.phar' generated.
    [phpab] 
[phar-set-timestamps] Setting timestamp of files in PHAR to 1728113935 (based on when tag 11.4.0 was created)
     [copy] Copying 1 file to /usr/local/src/phpunit/build/tmp
    [phpab] phpab 1.29.1 - Copyright (C) 2009 - 2024 by Arne Blankerts and Contributors
    [phpab] 
    [phpab] Scanning directory /usr/local/src/phpunit/build/tmp/phar-scoped
    [phpab] PHP Warning:  Undefined array key 1 in phar:///usr/local/src/phpunit/tools/phpab/phpab/Parser.php on line 425
    [phpab] PHP Warning:  Undefined array key 1 in phar:///usr/local/src/phpunit/tools/phpab/phpab/Parser.php on line 425
    [phpab] PHP Warning:  Undefined array key 1 in phar:///usr/local/src/phpunit/tools/phpab/phpab/Parser.php on line 425
    [phpab] PHP Warning:  Undefined array key 1 in phar:///usr/local/src/phpunit/tools/phpab/phpab/Parser.php on line 425
    [phpab] PHP Warning:  Undefined array key 1 in phar:///usr/local/src/phpunit/tools/phpab/phpab/Parser.php on line 425
    [phpab] PHP Warning:  Undefined array key 1 in phar:///usr/local/src/phpunit/tools/phpab/phpab/Parser.php on line 425
    [phpab] PHP Warning:  Undefined array key 1 in phar:///usr/local/src/phpunit/tools/phpab/phpab/Parser.php on line 425
    [phpab] PHP Warning:  Undefined array key 1 in phar:///usr/local/src/phpunit/tools/phpab/phpab/Parser.php on line 425
    [phpab] PHP Warning:  Undefined array key 1 in phar:///usr/local/src/phpunit/tools/phpab/phpab/Parser.php on line 425
    [phpab] PHP Warning:  Undefined array key 1 in phar:///usr/local/src/phpunit/tools/phpab/phpab/Parser.php on line 425
    [phpab] PHP Warning:  Undefined array key 1 in phar:///usr/local/src/phpunit/tools/phpab/phpab/Parser.php on line 425
    [phpab] 
    [phpab] phar archive '/usr/local/src/phpunit/build/artifacts/phpunit-11.4.0.phar' generated.
    [phpab] 
[phar-set-timestamps] Setting timestamp of files in PHAR to 1728113935 (based on when tag 11.4.0 was created)
   [delete] Deleting directory /usr/local/src/phpunit/build/tmp

signed-phar:

BUILD SUCCESSFUL
Total time: 13 seconds

I have not recently updated PHPAB, but I have not seen this warning before.

theseer commented 1 month ago

That's certainly a bug in my parser code.

Triggered by the use of constant named "NAMESPACE":

image

I'll have look in more detail later.

theseer commented 1 month ago

I'm actually inclined to call this a PHP Bug as the token_get_all function claims the constant name to be T_NAMESPACE while it should be T_STRING given the context.

I'm working on trying to find a reliable workaround.