Skip to content

Commit

Permalink
mention INIT_NS_CLASS_ENTRY macro
Browse files Browse the repository at this point in the history
  • Loading branch information
7snovic committed Sep 17, 2017
1 parent c9853a1 commit 6281350
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Book/classes_objects/simple_classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -78,6 +79,39 @@ 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;
}

Underneath the hood there are no big difference between the both ``INIT_CLASS_ENTRY`` and ``INIT_NS_CLASS_ENTRY`` macros, actually
``INIT_NS_CLASS_ENTRY`` uses ``INIT_CLASS_ENTRY`` macro with combining the two parameters namespace && classname::

#define INIT_NS_CLASS_ENTRY(class_container, ns, class_name, functions) \
INIT_CLASS_ENTRY(class_container, ZEND_NS_NAME(ns, class_name), functions)



Method definition and declaration
---------------------------------

Expand Down

0 comments on commit 6281350

Please sign in to comment.