Skip to content

Instantly share code, notes, and snippets.

Created December 2, 2019 20:52
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
A small script for easier management of multiple version of PHP with Homebrew on macOS
#!/usr/bin/env php
$ver = isset($argv[1]) ? $argv[1] : null;
if (!$ver) {
echo "Missing version argument\n";
if (!is_numeric($ver) || !preg_match("/^[5-9]\.[0-9]$/", $ver)) {
echo "Invalid version format, version number must be a decimal value with precision of one, e.g. 7.0\n";
$user = get_current_user();
$bash_profile = file_get_contents("/Users/$user/.bash_profile");
file_put_contents("/Users/$user/.bash_profile", preg_replace("/php@\d+\.\d+/", "php@$ver", $bash_profile));
echo "\n";
echo "PHP set to: $ver\n";
echo "Restart the terminal for the changes to take effect.\n";
echo "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment