-
-
Save rsky/813501 to your computer and use it in GitHub Desktop.
zend_fcall_info_init(), zend_fcall_info_call() のサンプル
This file contains hidden or 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
#ifdef HAVE_CONFIG_H | |
#include "config.h" | |
#endif | |
#include <php.h> | |
#include <ext/standard/info.h> | |
#include <Zend/zend_extensions.h> | |
static PHP_MINFO_FUNCTION(cb) | |
{ | |
php_write("hi!\n", 4 TSRMLS_CC); | |
} | |
static cb(INTERNAL_FUNCTION_PARAMETERS, int x) | |
{ | |
zval *retval = NULL, *args = NULL; | |
zval ***argv = NULL; | |
int argc = 0; | |
zend_fcall_info fci; | |
zend_fcall_info_cache fcc; | |
if (x == 0) { | |
zval *cb = NULL; | |
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, | |
"z*", &cb, &argv, &argc) | |
) { | |
return; | |
} | |
if (FAILURE == zend_fcall_info_init(cb, 0, &fci, &fcc, NULL, NULL TSRMLS_CC)) { | |
if (argc) { | |
efree(argv); | |
} | |
return; | |
} | |
} else { | |
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, | |
"f*", &fci, &fcc, &argv, &argc) | |
) { | |
return; | |
} | |
} | |
if (argc) { | |
int i; | |
zval **ppz; | |
MAKE_STD_ZVAL(args); | |
array_init_size(args, (uint)argc); | |
for (i = 0; i < argc; i++) { | |
ppz = *(argv + i); | |
SEPARATE_ZVAL_IF_NOT_REF(ppz); | |
add_next_index_zval(args, *ppz); | |
} | |
efree(argv); | |
} | |
if (SUCCESS == zend_fcall_info_call(&fci, &fcc, &retval, args TSRMLS_CC)) { | |
RETVAL_ZVAL(retval, 0, 1); | |
} else { | |
RETVAL_FALSE; | |
} | |
if (args) { | |
zval_ptr_dtor(&args); | |
} | |
} | |
static PHP_FUNCTION(cb1) | |
{ | |
cb(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); | |
} | |
static PHP_FUNCTION(cb2) | |
{ | |
cb(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); | |
} | |
static zend_function_entry cb_functions[] = { | |
PHP_FE(cb1, NULL) | |
PHP_FE(cb2, NULL) | |
{ NULL, NULL, NULL } | |
}; | |
static zend_module_entry cb_module_entry = { | |
STANDARD_MODULE_HEADER, | |
"cb", | |
cb_functions, | |
NULL, | |
NULL, | |
NULL, | |
NULL, | |
PHP_MINFO(cb), | |
"0.0.0", | |
STANDARD_MODULE_PROPERTIES | |
}; | |
#ifdef COMPILE_DL_CB | |
ZEND_GET_MODULE(cb) | |
#endif |
This file contains hidden or 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
PHP_ARG_ENABLE(cb, whether to enable cb support, | |
[ --enable-cb Enable cb support]) | |
if test "$PHP_CB" != "no"; then | |
PHP_NEW_EXTENSION(cb, cb.c, $ext_shared) | |
fi |
This file contains hidden or 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
php -d extension=cb.so -r 'cb1("ReflectionClass::export", "stdClass");' | |
php -d extension=cb.so -r 'cb1(array("ReflectionClass", "export"), "stdClass");' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment