Parse parameters. This step is implemented through the zend_parse_parameters function, which reads data from the input stack of function users, then convert to the corresponding function parameters and fill in the variables for later use by the core function code. The first parameter of zend_parse_parameters is the number of input parameters. It can be generated by the macro "ZEND_NUM_ARGS () TSRMLS_CC". The second parameter is a string, where each letter represents a variable type, we only have one string variable, so the second parameter is "s". Finally, each parameter requires some necessary local variable pointers for data storage, the following table lists the letters of different variable types and their required local variable pointers.
After the parameter resolution is complete, it is the core function code. Here we only output a line of characters, and php_printf is the Zend version of printf.
The final return value is also implemented through macro. The RETURN_TRUE macro returns the Boolean value "true ".
Use macros ZEND_BEGIN_ARG_INFO and ZEND_END_ARG_INFO to define parameter information.
Parameter information is a necessary part of the function. Do not go into details here and directly provide the corresponding code:
ZEND_BEGIN_ARG_INFO (arginfo_say_hello_func, 0) ZEND_END_ARG_INFO () for more information, see related macro definitions.
Use macro PHP_FE to add the function to say_hello_functions.
Finally, add the defined function and parameter information to the say_hello_functions array. The Code is as follows:
Const zend_function_entry say_hello_functions [] = {PHP_FE (say_hello_func, listener) {NULL, NULL, NULL}; this step is implemented through the PHP_EF macro. Note that the last line of this array must be {NULL, NULL, NULL}. Do not delete it.
The code for say_hello.c after compilation is as follows:
/* + Versions + | PHP Version 5 | + ------------------------------------------------------------------------ + | Copyright (c) 1997-2010 The PHP Group | + versions + | This source file is subject to version 3.01 of the PHP license, | that is bundled with this package in the file LICE Neuron, and is | available through the world-wide-web at the following url: | http://www.php.net/license/3_01.txt | If you did not receive a copy of the PHP license and are unable to | obtain it through the world-wide-web, please send a note to | license@php.net so we can mail you a copy immediately. | + ---------------------------------------------------------------------- + | Author: | + --- Authorization + * // * $ Id: header 297205 2010-03-30 21: 09: 07Z johannes ___ FCKpd ___ 14 nbsp; */# ifdef HAVE_CONFIG_H # include "config. h "# endif # include" php. h "# include" php_ini.h "# include" ext/standard/info. h "# include" php_say_hello.h "/* If you declare any globals in php_say_hello.h uncomment this: ZEND_DECLARE_MODULE_GLOBALS (say_hello) * // * T Rue global resources-no need for thread safety here */static int le_say_hello;/* {PHP_FUNCTION */PHP_FUNCTION (say_hello_func) {char * name; int name_len; if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC, "s", & name, & name_len) = FAILURE) {return;} php_printf ("Hello % s! ", Name); RETURN_TRUE;} ZEND_BEGIN_ARG_INFO (arginfo_say_hello_func, 0) ZEND_END_ARG_INFO () /* }}* // * {say_hello_functions [] ** Every user visible function must have an entry in say_hello_functions []. */const zend_function_entry say_hello_functions [] = {PHP_FE (say_hello_func, callback) {NULL, NULL}/* Must be the last line in say_hello_functions [] */}; /* }}* // * {detail */zend_module_entry detail = {# if detail> = 20010901 STANDARD_MODULE_HEADER, # endif "say_hello", say_hello_functions, NULL, NULL, NULL, PHP_MINFO (say_hello), # if ZEND_MODULE_API_NO> = 20010901 "0.1",/* Replace with version number for your extension */# endif STANDARD_MODULE_PROPERTIES }; /* }}*/# ifdef COMPILE_DL_SAY_HELLO ZEND_GET_MODULE (say_hello) # endif/* {PHP_MINFO_FUNCTION */PHP_MINFO_FUNCTION (say_hello) & nb