Skip to content

🧩 GetExtensions ​

Gets the list of all installed extension names in the current PHP environment.

When to use ​

Use it when you need to scan the set of available extensions, or to confirm that required extensions are present before installing dependencies.

Signature ​

go
func (c *Composer) GetExtensions() ([]string, error)

Parameters ​

ParameterTypeDescription
None—This method takes no parameters

Return value ​

  • []string: list of installed PHP extension names (the Loaded extensions: header line and empty lines are filtered out)
  • error: returned when 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)
    }

    extensions, err := comp.GetExtensions()
    if err != nil {
        log.Fatalf("failed to get PHP extensions: %v", err)
    }

    fmt.Println("Installed PHP extensions:")
    for _, ext := range extensions {
        fmt.Println("- " + ext)
    }
}

Advanced ​

  • This method runs composer run --show-extensions and parses the output line by line
  • To only check whether a single extension exists, use the lighter-weight HasExtension
  • To check whether extensions satisfy the platform constraints in composer.json, use CheckPlatform

Released under the MIT License