Last active
June 28, 2016 02:06
-
-
Save willitscale/e7fe971d4bc7653356d926c137ec70cc to your computer and use it in GitHub Desktop.
Example module source code for creating an PHP extension with hookable interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
zend_class_entry *hooker_bot_4000; | |
ZEND_BEGIN_ARG_INFO_EX(arginfo_void, 0, 0, 0) | |
ZEND_END_ARG_INFO() | |
const zend_function_entry hb4_functions[] = { | |
PHP_ABSTRACT_ME(HookerBot4000, hookerBot4000, arginfo_void) | |
PHP_FE_END | |
}; | |
zend_module_entry hb4_module_entry = { | |
#if ZEND_MODULE_API_NO >= 20010901 | |
STANDARD_MODULE_HEADER, | |
#endif | |
HB4_NAME, | |
hooker_bot_functions, | |
null, | |
null, | |
PHP_RINIT(hooker_bot_4000), | |
NULL, | |
NULL, | |
#if ZEND_MODULE_API_NO >= 20010901 | |
HB4_VERSION, | |
#endif | |
STANDARD_MODULE_PROPERTIES | |
}; | |
void * interface_implemented(zend_class_entry *ce TSRMLS_DC) | |
{ | |
php_printf("--------------interface_implemented----------------\n"); | |
return NULL; | |
} | |
void * never_called(zend_class_entry *ce TSRMLS_DC) | |
{ | |
php_printf("--------------never_called----------------\n"); | |
return NULL; | |
} | |
PHP_MINIT_FUNCTION(hello) | |
{ | |
zend_class_entry __tmpHB4; | |
INIT_CLASS_ENTRY(tmp_interface, "HookerBot4000", hooker_bot_4000_functions); | |
hooker_bot_4000 = zend_register_internal_interface(&__tmpHB4 TSRMLS_CC); | |
// Actually called | |
hooker_bot_4000->interface_gets_implemented = interface_implemented; // << Put Hooks here | |
// Never called (should seg fault if called) | |
hooker_bot_4000->constructor = never_called; | |
hooker_bot_4000->create_object = never_called; | |
hooker_bot_4000->__call = never_called; | |
hooker_bot_4000->__get = never_called; | |
hooker_bot_4000->__set = never_called; | |
// For full list check-out https://github.com/php/php-src/blob/c9a538cdb441437181913c09bdc4425596e51f46/Zend/zend_API.h#L194 | |
return SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment