Good news! PHP 7.1 is being actively supported through 21 Nov 2024. After that point, it's advisable to upgrade to the latest version, since the PHP team will only offer security-related support until 21 Nov 2024, at which point PHP 7.1 will be considered "end-of-life".
brew tap shivammathur/php
brew install shivammathur/php/[email protected]
brew link [email protected] --force
php -v
which php