Ocramius / PackageVersions

:package: Composer addon to efficiently get installed packages' version numbers
MIT License
3.22k stars 67 forks source link

PHP Parse error on composer update #62

Closed andrerom closed 6 years ago

andrerom commented 6 years ago
$ composer update
PHP Parse error:  syntax error, unexpected ':', expecting ';' or '{' in /Users/andrerom/Sites/www/ezplatform/vendor/ocramius/package-versions/src/PackageVersions/Installer.php on line 59

Reason: Switching between PHP versions when doing testing and this package not knowing when it should not load itself.

So improvment request: Please add some sanity check for php version running before loading plugin code to avoid this.

Ocramius commented 6 years ago

Switching between PHP versions when doing testing and this package not knowing when it should not load itself.

The lib has a strict php constraint

andrerom commented 6 years ago

doesn't help, this is composer plugin which is loaded by composer before packages get's updated, so wrong version is used.

One alternative is that you can argue composer should either bluntly delete vendor folder on updates / installs before loading anything. but..

Ocramius commented 6 years ago

The PHP installation is assumed to be relatively static, and I'd add that the current stable version of PHP is 7.1 already, so I don't think adding an enable/disable flag depending on the current SAT solver is a good idea, as switching environment on the same project should always come with a complete wipe of vendor for safety.

Even the plugin activation code itself may use 7.2+ features, so it will likely crash before it can even take a decision on its own.

andrerom commented 6 years ago

as switching environment on the same project should always come with a complete wipe of vendor for safety.

Actually it's just rm -Rf vendor/ocramius, everything else is fine ;)

Ocramius commented 6 years ago

@andrerom you could have a hundred plugins in there: they all activate ;-)

andrerom commented 6 years ago

None as aggressively using bleeding edge PHP features, and un-supporting prior PHP versions as often as on packages you are involved in ;)

Ocramius commented 6 years ago

You can lock onto previous versions of ocramius/package-versions if you want to support older PHP versions

andrerom commented 6 years ago

It's a dependency of my dependencies kind of thing, we don't use it, and don't have it on PHP 5.6 installs.

composer why: ocramius/proxy-manager 2.2.0 requires ocramius/package-versions (^1.1.3)

And we use proxy-manager for symfony lazy services.

Ocramius commented 6 years ago

Right, then I suggest using --no-scripts cor operations that may lead to eager dependency autoloading on antiquated PHP versions

On 21 Mar 2018 20:13, "André R." notifications@github.com wrote:

It's a dependency of my dependencies kind of thing, we don't use it, and don't have it on PHP 5.6 installs.

composer why: ocramius/proxy-manager 2.2.0 requires ocramius/package-versions (^1.1.3)

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/Ocramius/PackageVersions/issues/62#issuecomment-375063225, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJakOMe5N3Cwou_s4rn6gkuveMFAb-Zks5tgqZsgaJpZM4SzoA4 .

Allegro145 commented 6 years ago

Need help.. After successfully installed composer 1.7.1, when do a 'php composer.phar', I have the following error: Parse error: parse error, expecting ';'' or'{'' in /Users/user name/.composer/vendor/ocramius/package-versions/src/PackageVersions/Installer.php on line 59. Have removed and reinstalled older versions composer, still have the same error. Please someone could let me know how can I fix this and get the composer working again? Is there a way to start a fresh install if I have to?

Ocramius commented 6 years ago

Upgrade your PHP version and it should be alright

Allegro145 commented 6 years ago

I updated PHP to 7.2.7, MAMP 5.0.1 along with composer to 1.7.1 then I have this error. I am now back to MAMP 3.5, PHP 5.6.10 but still have the same error!

Ocramius commented 6 years ago

What's the output of php -v?

Allegro145 commented 6 years ago

PHP 5.5.38 (cli) (built: Oct 29 2017 20:49:07) . I installed composer 1.5.0 which didn't work.

Ocramius commented 6 years ago

Yeah, so upgrade it so that it says PHP 7.2.x (current stable) and you should be fine :)

Allegro145 commented 6 years ago

I ran this: curl -s https://php-osx.liip.ch/install.sh | bash -s 7.2 Saw the following: Installing package 7.2-10.10-frontenddev into root / Package 7.2-10.10-frontenddev is already installed at version 7.2.7-20180623-112258. You wanted to install version 7.2.7-20180623-112258. Finished. Also installed composer and saw: Composer (version 1.7.1) successfully installed to: Then did: php composer.phar and saw the error: Parse error: parse error, expecting ';'' or'{'' in /Users/Corbett Lyon/.composer/vendor/ocramius/package-versions/src/PackageVersions/Installer.php on line 59 check again php -v it is still showing: PHP 5.5.38 (cli) (built: Oct 29 2017 20:49:07) What went wrong?

Ocramius commented 6 years ago

This is most likely because the php you have in your $PATH is different from the one by Liip

Check the output of which php and you will see what it resolves to. Adding a symlink to the actual PHP installation you want in /usr/local/bin/ is generally solving this, as it "shadows" the other installation (presumably what comes with MacOS).

Allegro145 commented 6 years ago

Did a PATH=/usr/local/php5/bin:$PATH, then I can see php -v is 5.6.36 now but yet to figure out how to add a symlink as you said. Will update you on this. Thanks for your help so far!

andrerom commented 6 years ago

@Allegro145 If you ever downgrade PHP, like for instance if you have several PHP's installed in order to switch between projects.

Then if you on purpose want to run composer with older PHP then what has been used before on a project, then just run rm -Rf vendor/ocramius OR otherwise remove whole vendor/ before you run composer install or composer update to get the right package versions for your PHP version.

Not sure if you need it, but here is a liip script for switching between liip php versions: https://gist.github.com/andrerom/b360a1b2dbbebc6ec1861b8618d64e97

Allegro145 commented 6 years ago

@andrerom & @Ocramius I have a project works with PHP 5.6 & MAMP 3.5. I want to test if it will work with PHP 7.2. I installed the PHP 7.2 and composer 1.7 but messed it all up and got those errors. I am now trying to get a clean install of PHP and composer (outside the MAMP), no matter which version as long as they work. But no luck, currently 'php -v' is 5.6.36 and 'phpinfo.php' is 5.6.10. So composer 1.7 just doesn't work (same error as always).

I did 'rm -Rf vendor' then install composer 1.7, still no luck.

Ran a 'which php' is /usr/local/php5/bin/php and these two lines are in my ~/.bash_profile: alias phpmamp='/Applications/MAMP/bin/php/php5.5.10/bin/php' export PATH=/usr/local/php5/bin:$PATH

Can you see what have I done wrong or how should I fix this?

Ocramius commented 6 years ago

But no luck, currently 'php -v' is 5.6.36 and 'phpinfo.php' is 5.6.10.

Fixing this is going to fix your issues: 5.6 is extremely outdated, and you should move away from it regardless.

I have no idea how to fix MAMP, which is a separate project, but that's not an issue to be solved by this project.

Try putting your PHP 7.x path before the MAMP one in $PATH.

Locking the thread here: we went hugely off-topic.