Check which Composer dependencies requires PHP 8 or 8.1

Amit Merchant · August 11, 2022 ·

Oftentimes, you may find it useful to check whether which among all the packages requires/depends upon a certain PHP version.

For instance, Povilas Korop recently faced an issue where he wasn’t able to spin up a newly created Laravel project because of PHP compatibility issues with certain packages. So, he essentially wanted to check what packages depend upon PHP 8.1.

Willem Oostendorp then suggested a nice little Composer command that lets you do just that.

So, if we want to check which packages depend upon PHP 8.1, here’s how we can check it.

$ composer depends php | grep 8.1

As you can tell, we are using Composer’s depends command to first find out the packages that depend upon php and then pass that result to grep to further filter to show only packages that require PHP 8.1 specifically.

Here’s how the result would look like when you run this command

composer depends with grep

Learn the fundamentals of PHP 8 (and 8.1), the latest version of PHP, and how to use it today with my new book PHP 8 in a Nutshell. It's a no-fluff and easy-to-read guide to the latest features and nitty-gritty details of PHP 8. So, if you're looking for a quick and easy way to PHP 8, this is the book for you.

👋 Hi there! I'm Amit. I write articles about all things web development. If you like what I write and want me to continue doing the same, I would like you buy me some coffees. I'd highly appreciate that. Cheers!