From bc86ddb96a1913f1036f0662a0ca25ddf5090fe4 Mon Sep 17 00:00:00 2001 From: hassan Date: Sun, 17 Sep 2017 11:30:06 +0200 Subject: [PATCH] mention INIT_NS_CLASS_ENTRY macro --- Book/classes_objects/simple_classes.rst | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Book/classes_objects/simple_classes.rst b/Book/classes_objects/simple_classes.rst index 5be791ee..f996eb87 100644 --- a/Book/classes_objects/simple_classes.rst +++ b/Book/classes_objects/simple_classes.rst @@ -58,6 +58,7 @@ Then the main code follows: First a temporary class entry value ``tmp_ce`` is de ``INIT_CLASS_ENTRY``. After that the class is registered in the Zend Engine using ``zend_register_internal_class``. This function also returns the final class entry, so it can be stored in the global variable declared above. + To test that the class was registered properly you can run ``php --rc Test``, which should give an output along the following lines: @@ -78,6 +79,33 @@ following lines: As expected what you get is a totally empty class. + +Register a class with a specific namespace: +-------------------------------------------- +to register your class under a specific namespace you will need to use ``INIT_NS_CLASS_ENTRY`` instead of ``INIT_CLASS_ENTRY`` + +the ``INIT_NS_CLASS_ENTRY`` macro takes additional parameter -as a second parameter- to specify the namespace string. + +so our ``Test`` example would be as follows:: + + zend_class_entry *test_ce; + + const zend_function_entry test_functions[] = { + PHP_FE_END + }; + + PHP_MINIT_FUNCTION(test) + { + zend_class_entry tmp_ce; + INIT_NS_CLASS_ENTRY(tmp_ce, "TestNamespace", "Test", test_functions); + + test_ce = zend_register_internal_class(&tmp_ce TSRMLS_CC); + + return SUCCESS; + } + + + Method definition and declaration ---------------------------------