48

Today I ran composer update and the update broke my site completely. I found in the php.log the following information:

72.15.153.139 - - [11/Nov/2015:21:01:45 -0500] "GET / HTTP/1.1" 500 - "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0" [Wed Nov 11 21:01:48 2015] [error] [client 127.7.179.129] PHP Parse error: syntax error, unexpected 'function' (T_FUNCTION), expecting identifier (T_STRING) or \\ (T_NS_SEPARATOR) in /var/lib/openshift/55c481747628e14556000188/app-root/runtime/repo/config/vendor/danielstjules/stringy/tests/CreateTest.php on line 5 72.15.153.139 - - [11/Nov/2015:21:01:48 -0500] "GET / HTTP/1.1" 500 - "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0"

Seems that "danielstjules/stringy" is the one to blame. But how can I revert back to an older version (or using a news version?) of this package? I tried to modify composer.lock file, and changed

            "require": {
            "danielstjules/stringy": "~1.8",

to

        "require": {
            "danielstjules/stringy": "~1.9",

and run composer update again, but it gave the information:

Loading composer repositories with package information Updating dependencies (including require-dev) Nothing to install or update Writing lock file Generating autoload files PHP Parse error: syntax error, unexpected 'function' (T_FUNCTION), expecting identifier (T_STRING) or \ (T_NS_SEPARATOR) in /var/lib/openshift/55c481747628e14556000188/app-root/runtime/repo/config/vendor/danielstjules/stringy/tests/CreateTest.php on line 5 Script php artisan clear-compiled handling the post-update-cmd event returned with an error

[RuntimeException] Error Output: PHP Parse error: syntax error, unexpected 'function' (T_FUNC TION), expecting identifier (T_STRING) or \ (T_NS_SEPARATOR) in /var/lib/o penshift/55c481747628e14556000188/app-root/runtime/repo/config/vendor/danie lstjules/stringy/tests/CreateTest.php on line 5

How can I rollback this package? Thanks.

EDIT 2:

composer install will modify composer.lock automatically. I modified composer.json instead, and it fetched the old version 1.8 successfully.

But the build still failed. This issue description had the reason. But after I rm -rf test/, the problem was still there.

EDIT 3:

I tried the following:

  1. rm -rf vendor/
  2. composer update

The problem was gone.

5
  • 1
    Do you commit your composer.lock file? Commented Nov 12, 2015 at 2:25
  • 8
    Your composer.lock should be in version control. That'd allow you to just revert the changes to it, then do composer install to reinstall the known functional versions. Commented Nov 12, 2015 at 2:58
  • First, you should specify what exactly version you want update to. Modify composer.lock without using ~ character. If still broken, we have to using GIT or SVN to revert back to previous revision absolutely. Commented Nov 12, 2015 at 3:17
  • 1
    @VũTuấnAnh You should not modify composer.lock in any way. If you don't trust Composer to create a (according to version requirements) valid set of software packages, who should be able to do this? If there are versions that you want to avoid, modify composer.json to explicitly exclude them, then run update again. Or roll back to the previous set of versions. Commented Nov 16, 2015 at 19:53
  • @Sven You are right. I this case, i should modify composer.json instead. Thanks. Commented Nov 17, 2015 at 2:43

2 Answers 2

185

How to revert an update? Easy: Restore the composer.lock file from your version control system that was used before you updated.

The composer.lock exactly records which software was installed. So it is paramount to commit this file into version control in order to be able to go back to a working version in case of update failure.

Running composer install will always install the software versions recorded in composer.lock, it will only act like update if this file is not present.

Sign up to request clarification or add additional context in comments.

1 Comment

Just revert the files and run composer install. Worked!
14

If you check the composer version specification documentation, the ~ operator gets the latest version that is backwards-compatible according the principles of semantic versioning. That means that ~1.8 is equivalent to >=1.8 <2.0.0 and likewise ~1.9 is the same as >=1.9 <2.0.0. In other words, ~1.8 will return the SAME THING as ~1.9 if the latest version is >=1.9. If you really want to use version 1.8, just do this:

"danielstjules/stringy": "1.8",

That will get EXACTLY version 1.8. Of course you'll need to run composer update afterwards.

I find the composer versioning syntax tricky to remember myself.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.