feat(extgen): add support for `//export_php:namespace` by alexandre-daubois · Pull Request #1721 · php/frankenphp

Allows declaring symbols in a PHP namespace:

// export_php:namespace Go\Extension
package ext

import (
	"C"
	"github.com/dunglas/frankenphp"
	"strings"
	"unsafe"
)

// export_php:const
const MY_GLOBAL_CONSTANT = "Hello, World!"

// export_php:classconst MySuperClass
const STR_REVERSE = iota

// export_php:classconst MySuperClass
const STR_NORMAL = iota

// export_php:class MySuperClass
type MyClass struct {
	// internal fields
}

// export_php:method MySuperClass::setVersion(string $version): void
func (mc *MyClass) SetVersion(v *C.zend_string) {
	mc.Version = frankenphp.GoString(unsafe.Pointer(v))
}

This will declare every symbol in the Go\Extension namespace.

Declaring two namespaces in the same file would lead to an error like Error: parse source: parsing namespace: multiple namespace declarations found: first at line 3, second at line 4.