psysh: PsySH doesn't run on PHP 7.4 after recent update to 0.10.11
Environment
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal
$ php -v
PHP 7.4.3 (cli) (built: Oct 25 2021 18:20:54) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
with Xdebug v2.9.2, Copyright (c) 2002-2020, by Derick Rethans
$ composer show | grep psy
psy/psysh v0.10.11 An interactive shell for modern PHP.
The problem
$ ./vendor/bin/psysh ; echo $?
0
Workaround
It is working if I try to use “ready binary” from release page
$ curl -sL https://github.com/bobthecow/psysh/releases/download/v0.10.11/psysh-v0.10.11.tar.gz | tar xzf - && ./psysh
Using local PsySH version at ~/.config/composer
Psy Shell v0.10.11 (PHP 7.4.3 — cli) by Justin Hileman
>>>
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 29 (15 by maintainers)
Commits related to this issue
- Composer 2.2 PHP bin proxy compatibility. Fix early return when included from Composer's new PHP bin proxy scripts. Fixes #692 — committed to bobthecow/psysh by bobthecow 3 years ago
It may be an issue with a specific version of composer?
@bobthecow 👍 🎉 nope. everything works as expected after upgrading to 0.10.12. Thank you very much
No that is not the case. The autoloader does not set this variable, only the bin proxy does, so it’s really only available to scripts defined in the
"bin"key of composer.json and called via the proxy.Fix looks good to me though 👍🏻
I had a look at this and this is an issue that should ideally be fixed in PsySH because the issue-triggering change on Composer’s end is only going to get worse with the 2.2 release.
The change we did was that a few releases ago we started building PHP proxies instead of bash proxies for PHP composer-binaries, that allows people to use custom versions of php to call like
php7.4 vendor/bin/psyshif they don’t want to run with the default PHP. That requires that the bin file is either a symlink (not very cross-platform sadly) or a php file (our current solution). In 2.1 at some point we started using PHP proxies in some envs, but on 2.2 we will always use them as they fix other issues with path repos.So the problem on the PsySH end is that https://github.com/bobthecow/psysh/blob/38017532bba35d15d28dcc001b4274df0251c4a1/bin/psysh#L122-L126 detects it is being included and not run directly and it bails out.
Namely $trace is:
I am not sure why you have this code in there, but it’d be great if you can exclude it
if (preg_match('{[\\\\/]psysh$}', $trace[0]['file'])at least.Alternatively from Composer 2.2 on you’ll have as a bonus
$_composer_autoload_pathdefined as a global variable by the proxy, so you can detect you’re run by a composer proxy, and you can simply include that if it’s set instead of the whole 100 lines of autoload-detection you got there 😃See https://github.com/composer/composer/pull/10137 for related changes upcoming in Composer 2.2.
FYI https://github.com/composer/composer/issues/10310
Already searching if they have something similar in recent issues))