composer-php

Could not parse version constraint ~x.x: Invalid version string "~x.x"


I downloaded composer.phar with:

curl -sS https://getcomposer.org/installer | php

Then I run this command:

php composer.phar require mailgun/mailgun-php:~x.x

But I got this error:

[UnexpectedValueException]
Could not parse version constraint ~x.x: Invalid version string "~x.x"

Searching the Internet, most responses were to update the latest composer.phar. But I just downloaded it. If it was the case, how do I update? (This is on a Mac OS X ver 10.10.5)


Solution

  • In version constraints, x means any number. So you say any number.any number in other words: Just get me a random release.

    ~1.2 means >=1.2,<2.0. In a more formal way: ~y.z means >=y.z,<(y+1).0.

    What you say is give me at least any release, but lower than any release + 1. This is of course not resolvable. If it was, it's highly dangerous as you allow all releases.

    So you have to change your version constraint to something better or more secure. For instance, if you want any 1.x release, use 1.x, 1.* or ~1.0. If you want any 1.x release or any 2.x release, use 1.x|2.x or any other variant mentioned before.

    For more information about version constraints, read the Composer documentation. See also a usefull version constraint tester to test your version constraints.