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

phpmd.phar inclusion via other PHP script is impossible #1074

Open
6 tasks done
vertexvaar opened this issue Mar 1, 2024 · 4 comments
Open
6 tasks done

phpmd.phar inclusion via other PHP script is impossible #1074

vertexvaar opened this issue Mar 1, 2024 · 4 comments

Comments

@vertexvaar
Copy link

  • PHPMD version: Tested with 2.15, but any version since 2011 is affected (Since 9a8b521)
  • PHP Version: PHP 8.1-8.3 (irrelevant)
  • Installation type: phar via composer (I've started an experimental project that tries to provide phars for all good and relevant projects: https://packagist.org/packages/composer-phar/phpmd).
  • Operating System / Distribution & Version: Ubuntu in Docker

Current Behavior

Executing vendor/bin/phpmd.phar does do nothing (vendor/composer-phar/phpmd/phpmd.phar works as expected)

Expected Behavior

Executing the phpmd.phar via the generated composer wrapper works

Steps To Reproduce:

  • composer req composer-phar/phpmd
  • vendor/bin/phpmd.phar <dir> ansi codestyle

Details

A change introduced 15 years ago, which i don't know if its still relevant, prohibits the execution of PHP Mess Detector when included by other Script.
The phpmd.phar checks if the executed script equals the actual phar file (itself) and does nothing, if it was included.

I am not aware of any reason or requirement to perform this check. Maybe there actually isn't any. I would be glad if the check could be removed, so the composer-phar project can move on and provide the phpmd.pahr to anyone via composer.

The technical details are:

  • Composer install the package
  • The package defines phpmd.phar as bin
  • Composer creates a wrapper script in vendor/bin/phpmd.phar whith return include __DIR__ . '/..'.'/composer-phar/phpmd/phpmd.phar';
  • When included, the condition isset($argv) && realpath($argv[0]) === __FILE__ in phpmd.phar/.phar/stub.php evaluates to false.
  • __HALT_COMPILER(); is the next and inherently last instruction processed by PHP

YES, i am aware of PHIVE. If you don't mind I would like to exclude PHIVE and the whole "just curl/wget the phar" from this discussion.

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".
@AJenbo
Copy link
Member

AJenbo commented Mar 1, 2024

Please correct the license information for the package.

@vertexvaar
Copy link
Author

@AJenbo the whole project is still WIP. I will extend the PHAR crawler script to fetch the licenses from the source repos ASAP

@vertexvaar
Copy link
Author

@AJenbo the whole project is still WIP. I will extend the PHAR crawler script to fetch the licenses from the source repos ASAP

✔️ License added (for all projects, not just phpmd 😉 )

@AJenbo
Copy link
Member

AJenbo commented Mar 2, 2024

Nice work 👏

It's a nice project and I can see it being helpful.

@ravage84 ravage84 added this to the 2.x (unspecific) milestone May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants