@@ -58,6 +58,7 @@ Then the main code follows: First a temporary class entry value ``tmp_ce`` is de
5858``INIT_CLASS_ENTRY ``. After that the class is registered in the Zend Engine using ``zend_register_internal_class ``. This
5959function also returns the final class entry, so it can be stored in the global variable declared above.
6060
61+
6162To test that the class was registered properly you can run ``php --rc Test ``, which should give an output along the
6263following lines:
6364
@@ -78,6 +79,39 @@ following lines:
7879
7980 As expected what you get is a totally empty class.
8081
82+
83+ Register a class with a specific namespace:
84+ --------------------------------------------
85+ to register your class under a specific namespace you will need to use ``INIT_NS_CLASS_ENTRY `` instead of ``INIT_CLASS_ENTRY ``
86+
87+ the ``INIT_NS_CLASS_ENTRY `` macro takes additional parameter -as a second parameter- to specify the namespace string.
88+
89+ so our ``Test `` example would be as follows::
90+
91+ zend_class_entry *test_ce;
92+
93+ const zend_function_entry test_functions[] = {
94+ PHP_FE_END
95+ };
96+
97+ PHP_MINIT_FUNCTION(test)
98+ {
99+ zend_class_entry tmp_ce;
100+ INIT_NS_CLASS_ENTRY(tmp_ce, "TestNamespace", "Test", test_functions);
101+
102+ test_ce = zend_register_internal_class(&tmp_ce TSRMLS_CC);
103+
104+ return SUCCESS;
105+ }
106+
107+ Underneath the hood there are no big difference between the both ``INIT_CLASS_ENTRY `` and ``INIT_NS_CLASS_ENTRY `` macros, actually
108+ ``INIT_NS_CLASS_ENTRY `` uses ``INIT_CLASS_ENTRY `` macro with combining the two parameters namespace && classname::
109+
110+ #define INIT_NS_CLASS_ENTRY(class_container, ns, class_name, functions) \
111+ INIT_CLASS_ENTRY(class_container, ZEND_NS_NAME(ns, class_name), functions)
112+
113+
114+
81115Method definition and declaration
82116---------------------------------
83117
0 commit comments