xref: /PHP-8.1/ext/skeleton/skeleton.c (revision 2b5de6f8)
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 #include "%EXTNAME%_arginfo.h"
11 
12 /* For compatibility with older PHP versions */
13 #ifndef ZEND_PARSE_PARAMETERS_NONE
14 #define ZEND_PARSE_PARAMETERS_NONE() \
15 	ZEND_PARSE_PARAMETERS_START(0, 0) \
16 	ZEND_PARSE_PARAMETERS_END()
17 #endif
18 
19 /* {{{ void test1() */
20 PHP_FUNCTION(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 test2( [ string $var ] ) */
PHP_FUNCTION(test2)29 PHP_FUNCTION(test2)
30 {
31 	char *var = "World";
32 	size_t var_len = sizeof("World") - 1;
33 	zend_string *retval;
34 
35 	ZEND_PARSE_PARAMETERS_START(0, 1)
36 		Z_PARAM_OPTIONAL
37 		Z_PARAM_STRING(var, var_len)
38 	ZEND_PARSE_PARAMETERS_END();
39 
40 	retval = strpprintf(0, "Hello %s", var);
41 
42 	RETURN_STR(retval);
43 }
44 /* }}}*/
45 
46 /* {{{ PHP_RINIT_FUNCTION */
47 PHP_RINIT_FUNCTION(%EXTNAME%)
48 {
49 #if defined(ZTS) && defined(COMPILE_DL_%EXTNAMECAPS%)
50 	ZEND_TSRMLS_CACHE_UPDATE();
51 #endif
52 
53 	return SUCCESS;
54 }
55 /* }}} */
56 
57 /* {{{ PHP_MINFO_FUNCTION */
58 PHP_MINFO_FUNCTION(%EXTNAME%)
59 {
60 	php_info_print_table_start();
61 	php_info_print_table_header(2, "%EXTNAME% support", "enabled");
62 	php_info_print_table_end();
63 }
64 /* }}} */
65 
66 /* {{{ %EXTNAME%_module_entry */
67 zend_module_entry %EXTNAME%_module_entry = {
68 	STANDARD_MODULE_HEADER,
69 	"%EXTNAME%",					/* Extension name */
70 	ext_functions,					/* zend_function_entry */
71 	NULL,							/* PHP_MINIT - Module initialization */
72 	NULL,							/* PHP_MSHUTDOWN - Module shutdown */
73 	PHP_RINIT(%EXTNAME%),			/* PHP_RINIT - Request initialization */
74 	NULL,							/* PHP_RSHUTDOWN - Request shutdown */
75 	PHP_MINFO(%EXTNAME%),			/* PHP_MINFO - Module info */
76 	PHP_%EXTNAMECAPS%_VERSION,		/* Version */
77 	STANDARD_MODULE_PROPERTIES
78 };
79 /* }}} */
80 
81 #ifdef COMPILE_DL_%EXTNAMECAPS%
82 # ifdef ZTS
83 ZEND_TSRMLS_CACHE_DEFINE()
84 # endif
85 ZEND_GET_MODULE(%EXTNAME%)
86 #endif
87