phpDocumentor: Phar doesn't work after 3.3.1

Running the phpDocumentor phar worked fine for me up to 3.3.1 but it stopped working for 3.4.0. This cropped up initially in a gitlab pipeline, it had worked fine on Aug 15 but it stopped working Aug 16. Nothing in the pipeline environment changed between runs. I was also able to replicate the issue on my personal machine.

Expected behavior

Running the phpDocumentor phar file should work.

$ curl -L https://github.com/phpDocumentor/phpDocumentor/releases/download/v3.3.1/phpDocumentor.phar > phpdoc
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 22.0M  100 22.0M    0     0  19.2M      0  0:00:01  0:00:01 --:--:-- 23.8M
$ chmod +x phpdoc
$ ./phpdoc
phpDocumentor v3.3.1

Parsing files
 129/129 [============================] 100%
Applying transformations (can take a while)
 4/4 [============================] 100%
All done in 1 seconds!

Actual behavior

The phpDocumentor phar complains about Failed to open stream: phar error: no directory in "phar:///[redacted]/phpdoc/bin/phpdoc"

$ curl -L https://github.com/phpDocumentor/phpDocumentor/releases/download/v3.4.0/phpDocumentor.phar > phpdoc
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 14.4M  100 14.4M    0     0  9093k      0  0:00:01  0:00:01 --:--:-- 13.5M
$ chmod +x phpdoc
$ ./phpdoc
PHP Warning:  require(phar:///[redacted]/phpdoc/bin/phpdoc): Failed to open stream: phar error: no directory in "phar:///[redacted]/phpdoc/bin/phpdoc", must have at least phar:///[redacted]/phpdoc/bin/phpdoc/ for root directory (always use full p
ath to a new phar) in /[redacted]/phpdoc on line 10
PHP Fatal error:  Uncaught Error: Failed opening required 'phar:///[redacted]/phpdoc/bin/phpdoc' (include_path='.:') in [redacted]/phpdoc:10
Stack trace:
#0 {main}
  thrown in /[redacted]/phpdoc on line 10

Steps to reproduce the problem

  1. Download phar
  2. Set executable flag
  3. Run the phar file

Your environment

  • Version used: 3.4.0
  • Install method: phar
  • PHP version: 8.2.9 and 8.1.14
  • Operating system and version: Arch Linux and Ubuntu 20.04.5 LTS

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Reactions: 2
  • Comments: 19 (11 by maintainers)

Commits related to this issue

Most upvoted comments

v3.4.1 willl be available within minutes. This should fix your issue.

Thanks for all the reports!

php 7.4 is not supported anymore.

I created a new issue, please continue there, as this issue was different.

Hi@all, I’m facing a similar problem, but only the second time I run the phar.

My environment

  • Version used: 3.4.1
  • Install method: phar
  • PHP version: 8.1.2
  • Operating system and version: Ubuntu Linux 22.04.3 LTS
  • I’ve the zlib extension installed and working
  • I’m running the phar as normal user.

Steps to reproduce the problem:

FYI: I’m working into /tmp directory.

  1. Download phar $ wget https://github.com/phpDocumentor/phpDocumentor/releases/download/v3.4.1/phpDocumentor.phar
  2. Set executable flag $ chmod +x phpDocumentor.phar
  3. Run the phar file $ ./phpDocumentor help (help command, for instance)

After these steps. from the second time I launch the phar onwards: $ ./phpDocumentor help

I obtain the following result:

PHP Notice: require(): zlib: data error in /tmp/phpDocumentor.phar on line 11 PHP Warning: require(phar://phpdocumentor.phar/bin/phpdoc): Failed to open stream: phar error: internal corruption of phar “/tmp/phpDocumentor.phar” (actual filesize mismatch on file “bin/phpdoc”) in /tmp/phpDocumentor.phar on line 11 PHP Fatal error: Uncaught Error: Failed opening required ‘phar://phpdocumentor.phar/bin/phpdoc’ (include_path=‘.:/usr/share/php’) in /tmp/phpDocumentor.phar:11 Stack trace: #0 {main} thrown in /tmp/phpDocumentor.phar on line 11

Additionally I’ve extracted the phar before and after running it and seen that in the second extraction there are missing files. One for all phar://phpDocumentor.phar/bin/phpdoc

I think the problem you are facing is caused by the fact the new release is a zipped phar file to reduce the size of the package. When I download the file using your curl command I get the same error however when I use the original file file it still works.

Making a symlink does work, that might help you to solve your issue with to much impact.

It’s unclear to me right now why this happens, I will investigate this.