xref: /PHP-7.4/ext/skeleton/skeleton.c (revision 92ac598a)
1 %HEADER%
2 
3 #ifdef HAVE_CONFIG_H
4 # include "config.h"
5 #endif
6 
7 #include "php.h"
8 #include "ext/standard/info.h"
9 #include "php_%EXTNAME%.h"
10 
11 /* For compatibility with older PHP versions */
12 #ifndef ZEND_PARSE_PARAMETERS_NONE
13 #define ZEND_PARSE_PARAMETERS_NONE() \
14 	ZEND_PARSE_PARAMETERS_START(0, 0) \
15 	ZEND_PARSE_PARAMETERS_END()
16 #endif
17 
18 /* {{{ void %EXTNAME%_test1()
19  */
20 PHP_FUNCTION(%EXTNAME%_test1)
21 {
22 	ZEND_PARSE_PARAMETERS_NONE();
23 
24 	php_printf("The extension %s is loaded and working!\r\n", "%EXTNAME%");
25 }
26 /* }}} */
27 
28 /* {{{ string %EXTNAME%_test2( [ string $var ] )
29  */
30 PHP_FUNCTION(%EXTNAME%_test2)
31 {
32 	char *var = "World";
33 	size_t var_len = sizeof("World") - 1;
34 	zend_string *retval;
35 
36 	ZEND_PARSE_PARAMETERS_START(0, 1)
37 		Z_PARAM_OPTIONAL
38 		Z_PARAM_STRING(var, var_len)
39 	ZEND_PARSE_PARAMETERS_END();
40 
41 	retval = strpprintf(0, "Hello %s", var);
42 
43 	RETURN_STR(retval);
44 }
45 /* }}}*/
46 
47 /* {{{ PHP_RINIT_FUNCTION
48  */
49 PHP_RINIT_FUNCTION(%EXTNAME%)
50 {
51 #if defined(ZTS) && defined(COMPILE_DL_%EXTNAMECAPS%)
52 	ZEND_TSRMLS_CACHE_UPDATE();
53 #endif
54 
55 	return SUCCESS;
56 }
57 /* }}} */
58 
59 /* {{{ PHP_MINFO_FUNCTION
60  */
61 PHP_MINFO_FUNCTION(%EXTNAME%)
62 {
63 	php_info_print_table_start();
64 	php_info_print_table_header(2, "%EXTNAME% support", "enabled");
65 	php_info_print_table_end();
66 }
67 /* }}} */
68 
69 /* {{{ arginfo
70  */
71 ZEND_BEGIN_ARG_INFO(arginfo_%EXTNAME%_test1, 0)
72 ZEND_END_ARG_INFO()
73 
74 ZEND_BEGIN_ARG_INFO(arginfo_%EXTNAME%_test2, 0)
75 	ZEND_ARG_INFO(0, str)
76 ZEND_END_ARG_INFO()
77 /* }}} */
78 
79 /* {{{ %EXTNAME%_functions[]
80  */
81 static const zend_function_entry %EXTNAME%_functions[] = {
82 	PHP_FE(%EXTNAME%_test1,		arginfo_%EXTNAME%_test1)
83 	PHP_FE(%EXTNAME%_test2,		arginfo_%EXTNAME%_test2)
84 	PHP_FE_END
85 };
86 /* }}} */
87 
88 /* {{{ %EXTNAME%_module_entry
89  */
90 zend_module_entry %EXTNAME%_module_entry = {
91 	STANDARD_MODULE_HEADER,
92 	"%EXTNAME%",					/* Extension name */
93 	%EXTNAME%_functions,			/* zend_function_entry */
94 	NULL,							/* PHP_MINIT - Module initialization */
95 	NULL,							/* PHP_MSHUTDOWN - Module shutdown */
96 	PHP_RINIT(%EXTNAME%),			/* PHP_RINIT - Request initialization */
97 	NULL,							/* PHP_RSHUTDOWN - Request shutdown */
98 	PHP_MINFO(%EXTNAME%),			/* PHP_MINFO - Module info */
99 	PHP_%EXTNAMECAPS%_VERSION,		/* Version */
100 	STANDARD_MODULE_PROPERTIES
101 };
102 /* }}} */
103 
104 #ifdef COMPILE_DL_%EXTNAMECAPS%
105 # ifdef ZTS
106 ZEND_TSRMLS_CACHE_DEFINE()
107 # endif
108 ZEND_GET_MODULE(%EXTNAME%)
109 #endif
110