Skip to content

Conversation

@alexandre-daubois
Copy link
Member

@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
@dunglas dunglas merged commit 1804e36 into php:main Jul 16, 2025
43 checks passed
@dunglas
Copy link
Member

dunglas commented Jul 16, 2025

Thanks!!

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.

2 participants