Skip to content

🔖 GetPHPVersion

Returns the current PHP version string.

When to Use

Use this when you need to display the PHP version or check whether Composer's minimum PHP requirement is met. 📈

Signature

go
func GetPHPVersion() (string, error)

Parameters

ParameterTypeDescription
NonePackage-level function, takes no parameters

Return Value

  • string: The PHP version number, e.g. 8.3.6.
  • error: Returns a wrapped error on execution failure (usually because PHP is not installed). ⚠️

Example

go
package main

import (
	"fmt"
	"log"

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

func main() {
	version, err := installer.GetPHPVersion()
	if err != nil {
		log.Fatalf("failed to get PHP version: %v", err)
	}
	fmt.Printf("PHP version: %s\n", version)
}

Advanced

  • Implemented by running php -r "echo PHP_VERSION;"; the result is trimmed of surrounding whitespace. 🐘
  • You can use HasPHP beforehand to avoid errors. ✅
  • This result is written into InstallResult.PHPVersion; see InstallWithProgress. 🔗

Released under the MIT License