Install Unsupported PHP using Brew
Brew by default doesn't install unsupported software versions. Like at this time, php7.3 was no longer supported.
Installing it disables it and install instead the latest version (8.1.3 at this time).
1~$ brew install php@7.3
2Running `brew update --preinstall`...
3==> Auto-updated Homebrew!
4Updated 2 taps (homebrew/core and homebrew/cask).
5==> Updated Formulae
6Updated 2 formulae.
7==> Updated Casks
8Updated 6 casks.
9
10Error: php@7.3 has been disabled because it is a versioned formula!
11
12~$ php --version
13PHP 8.1.3 (cli) (built: Mar 1 2022 01:17:32) (NTS)
14Copyright (c) The PHP Group
15Zend Engine v4.1.3, Copyright (c) Zend Technologies
16 with Zend OPcache v8.1.3, Copyright (c), by Zend Technologies
Proper instalation of unsupported packages
1~$ brew tap shivammathur/php
2==> Tapping shivammathur/php
3Cloning into '/usr/local/Homebrew/Library/Taps/shivammathur/homebrew-php'...
4remote: Enumerating objects: 9826, done.
5remote: Counting objects: 100% (48/48), done.
6remote: Compressing objects: 100% (30/30), done.
7remote: Total 9826 (delta 33), reused 27 (delta 18), pack-reused 9778
8Receiving objects: 100% (9826/9826), 1.28 MiB | 811.00 KiB/s, done.
9Resolving deltas: 100% (7564/7564), done.
10Tapped 9 formulae (57 files, 1.8MB).
then
1~$ brew install shivammathur/php/php@7.3
Then force link it
1brew link --overwrite --force shivammathur/php/php@7.3
Add to PATH in .bash_profile and re-source
1/usr/local/opt/php@7.3/bin:/usr/local/opt/php@7.3/sbin:/usr/local/bin
See further details in https://github.com/shivammathur/homebrew-php