🐘 GetPHPVersion
Gets the PHP version number currently used by the system.
When to use
Use this when you need to obtain the PHP major version string for log output, compatibility checks, or environment probing.
Signature
go
func (c *Composer) GetPHPVersion() (string, error)Parameters
| Parameter | Type | Description |
|---|---|---|
| None | — | This method takes no parameters |
Return value
string: The current PHP version number, e.g.8.2.14; returns an empty string if it cannot be parsederror: Returns an error when the command execution fails
Example
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/composer"
)
func main() {
comp, err := composer.New(composer.DefaultOptions())
if err != nil {
log.Fatal(err)
}
phpVersion, err := comp.GetPHPVersion()
if err != nil {
log.Fatalf("Failed to get PHP version: %v", err)
}
fmt.Printf("Current PHP version: %s\n", phpVersion)
}Advanced
- This method executes
composer run --php-show-versionand extracts the version number from the line starting withPHP - For Composer's own version information (including major/minor/patch numbers), see
GetVersionInfoin result_types - To check whether a certain version constraint is satisfied, use IsPlatformAvailable