Skip to content

🐘 HasPHP

Checks whether PHP is available on the system.

When to Use

Use this when you need to confirm PHP is present before installing Composer or running any PHP-dependent command. ✅

Signature

go
func HasPHP() bool

Parameters

ParameterTypeDescription
NonePackage-level function, takes no parameters

Return Value

  • bool: true means PHP is available; false means it was not found.

Example

go
package main

import (
	"fmt"

	"github.com/scagogogo/composer-skills/pkg/installer"
)

func main() {
	if installer.HasPHP() {
		fmt.Println("PHP is ready")
	} else {
		fmt.Println("PHP is missing; install it first")
	}
}

Advanced

  • Detection paths: first checks php in PATH, then /usr/bin/php, /usr/local/bin/php, and /opt/homebrew/bin/php. 🔍
  • If missing and you want to auto-install, use InstallPHP. 🛠️
  • If you need the version number, use GetPHPVersion. 🔖
  • This is the precondition check inside Installer.Install and InstallWithProgress. 🔗

Released under the MIT License