PHP_MINIT_FUNCTION(myextension) { /* Initialization code for myextension */ }
PHP_MINIT_FUNCTION(mylibrary) { /* Register constants */ REGISTER_LONG_CONSTANT("MY_LIBRARY_CONSTANT_ONE", 1, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MY_LIBRARY_CONSTANT_TWO", 2, CONST_CS | CONST_PERSISTENT); /* Register classes */ zend_class_entry ce; INIT_CLASS_ENTRY(ce, "MyLibraryClass", mylibrary_class_functions); mylibrary_class_entry = zend_register_internal_class(&ce TSRMLS_CC); /* Register functions */ REGISTER_STRING_FUNCTION("mylibrary_hello_world", mylibrary_hello_world, NULL, ZEND_ACC_PUBLIC); return SUCCESS; }Here, we are defining a PHP library called "mylibrary". During module initialization, we are registering constants, classes, and functions that will be available to any PHP code that uses our library. In this example, we are registering two constants ("MY_LIBRARY_CONSTANT_ONE" and "MY_LIBRARY_CONSTANT_TWO"), one class ("MyLibraryClass"), and one function ("mylibrary_hello_world"). The function will return the string "Hello, world!" when called. By using the module_init() function to define the initialization code for our library, we can ensure that our library is properly registered and available to other PHP code. In conclusion, the module_init() function is an important part of creating PHP extensions and libraries. It allows for the initialization of PHP modules, which is essential for adding new functionality to PHP.