求教php扩展中实例化对象并调用方法
1个回答
2018-09-16 · 百度知道官方认证企业
腾讯电脑管家
腾讯电脑管家是腾讯公司推出的免费安全管理软件,能有效预防和解决计算机上常见的安全风险,并帮助用户解决各种电脑“疑难杂症”、优化系统和网络环境,是中国综合能力最强、最稳定的安全软件。
向TA提问
关注
展开全部
如下:
ZEND_FUNCTION(call_say){
//调用myclass中的say方法
zval *obj,*method_construct,*method_say,*name,*age;
int name_len,age_len;
zend_uint param_count=ZEND_NUM_ARGS();
zval *params[param_count];
MAKE_STD_ZVAL(obj);
MAKE_STD_ZVAL(method_construct);
MAKE_STD_ZVAL(method_say);
object_init_ex(obj, people_ce);
ZVAL_STRINGL(method_construct,"__construct",strlen("__construct"),1);
ZVAL_STRINGL(method_say,"say",strlen("say"),1);
//获取参数
if(zend_parse_parameters(param_count TSRMLS_CC,"ss",&name,&name_len,&age,&age_len)==FAILURE){
WRONG_PARAM_COUNT;
}
params[0]=name;
params[1]=age;
//__construct中存在参数
call_user_function(NULL, &obj, method_construct, NULL,param_count,params TSRMLS_CC);
call_user_function(NULL, &obj, method_say,NULL,0,NULL TSRMLS_CC);
zval_ptr_dtor(&obj);
zval_ptr_dtor(&method_construct);
zval_ptr_dtor(&method_say);
return;
ZEND_FUNCTION(call_say){
//调用myclass中的say方法
zval *obj,*method_construct,*method_say,*name,*age;
int name_len,age_len;
zend_uint param_count=ZEND_NUM_ARGS();
zval *params[param_count];
MAKE_STD_ZVAL(obj);
MAKE_STD_ZVAL(method_construct);
MAKE_STD_ZVAL(method_say);
object_init_ex(obj, people_ce);
ZVAL_STRINGL(method_construct,"__construct",strlen("__construct"),1);
ZVAL_STRINGL(method_say,"say",strlen("say"),1);
//获取参数
if(zend_parse_parameters(param_count TSRMLS_CC,"ss",&name,&name_len,&age,&age_len)==FAILURE){
WRONG_PARAM_COUNT;
}
params[0]=name;
params[1]=age;
//__construct中存在参数
call_user_function(NULL, &obj, method_construct, NULL,param_count,params TSRMLS_CC);
call_user_function(NULL, &obj, method_say,NULL,0,NULL TSRMLS_CC);
zval_ptr_dtor(&obj);
zval_ptr_dtor(&method_construct);
zval_ptr_dtor(&method_say);
return;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询