Skip to content

feat(extgen): add support for //export_php:namespace #1721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alexandre-daubois
Copy link
Contributor

@alexandre-daubois alexandre-daubois commented Jul 3, 2025

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.

@alexandre-daubois alexandre-daubois force-pushed the support-ns branch 3 times, most recently from d1a3958 to b3fcceb Compare July 5, 2025 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant