Can I put PHP extension classes, functions, etc. in a namespace?

c, php, php-extension

Solution

Putting a class in a namespace is very simple. Where normally you would initialize a class with

zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "MyClass", my_class_methods);

instead write the second line as

INIT_CLASS_ENTRY(ce, "MyNamespace\\MyClass", my_class_methods);

The namespace does not need to be included in the method declarations or in the members of the `my_class_methods` array to properly match them with the class.

Problem

I am writing a PHP extension in C, and I would like to put the classes, functions, and variables I am creating in a namespace. I have not been able to find anything in the extension documentation regarding namespaces. To be clear, I want the equivalent of ``` namespace MyNamespace{ class MyClass{ } } ``` but in a C extension. More specifically, I am looking for a function or macro in the Zend C API that allows me to assign a PHP namespace to a class or function I have written in C. Is this possible?

Original source

Related problems