From 546f05abd18b6b007e1a37b2810c517a8fbcd786 Mon Sep 17 00:00:00 2001 From: hassan Date: Mon, 16 Oct 2017 23:02:16 +0200 Subject: [PATCH] mention ZEND_NS_NAMED_FE macro --- Book/php7/extensions_design/php_functions.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Book/php7/extensions_design/php_functions.rst b/Book/php7/extensions_design/php_functions.rst index 5cba9bc8..e971c60e 100644 --- a/Book/php7/extensions_design/php_functions.rst +++ b/Book/php7/extensions_design/php_functions.rst @@ -109,6 +109,23 @@ Then, we gather that function symbol and add it to the ``pib_functions`` vector. functions using the ``PHP_FE`` macro. That latter needs the PHP function name, and an argument vector which we passed NULL for the moment. +You can register your function under a specific namespace using the `ZEND_NS_NAMED_FE` macro, this macro +takes four parameters : + + * the namespace string, e.g: "Pib\\Book". + * the function name, this will be the final function name under the new namespace, for example lets call it : `f2c`. + * the function handler, from our example: `fahrenheit_to_celsius`. + * the arg info which will be covered in this chapter. + +So the final `zend_function_entry` would be something like:: + + static const zend_function_entry pib_functions[] = + { + ZEND_NS_NAMED_FE("Pib\\Book", f2c, fahrenheit_to_celsius, NULL) + }; + +Note that your new function will take a new name here which will be `f2c`. + Into our *php_pib.h* header file, we should here declare our function, like the C language tells us to do so:: /* pib.h */