Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP Zend引擎扩展静态方法调用_Php_C_Php Extension_Php Internals - Fatal编程技术网

PHP Zend引擎扩展静态方法调用

PHP Zend引擎扩展静态方法调用,php,c,php-extension,php-internals,Php,C,Php Extension,Php Internals,我正在编写一个PHP扩展。在C代码中,我尝试在PHP代码中调用一个静态方法 PHP方法如下所示: <?php class Model { static method GetModelById($id) { ... } } ?> if( call_user_function_ex( &((*ce)->function_table), NULL, &fname, &retval_ptr, 1, func_params

我正在编写一个PHP扩展。在C代码中,我尝试在PHP代码中调用一个静态方法

PHP方法如下所示:

<?php
class Model {
  static method GetModelById($id) { ... }
}
?>
if( call_user_function_ex(
      &((*ce)->function_table),
      NULL, &fname, &retval_ptr,
      1, func_params, 0, NULL TSRMLS_CC
    ) == SUCCESS
){
  // do some stuff here ...
}
。。。其中所有传递的参数都应包含正确的值。奇怪的是:如果我针对PHP5.2编译扩展,代码运行良好,如果我针对PHP5.3编译扩展,方法调用失败,没有错误消息

我还尝试了
zend\u call\u方法
,但两个版本都没有成功

有人能给我小费吗?如何从C调用静态方法

提前谢谢

编辑

对不起,伙计们,我是通过zend_call_方法工作的,就像这样:

if( zend_call_method( NULL, *ce, NULL, 
                     "getmodelbyid", 
                     strlen("getmodelbyid"), 
                     &retval_ptr, 1, p1, 
                     NULL TSRMLS_CC ) == FAILURE) {
    php_printf("gosh!");
} 
else {
    php_printf("yep!"); 
}
。。。所以我学会了:

  • 函数名必须始终使用小写
  • 当涉及到字符串长度时,您最好看看PHP的源代码(
    zend_call_method
    adds+1)
  • 虽然我是C新手,但我认为PHP代码库在很多方面都被过度编译了


    希望这对其他人有帮助

    Peter,你介意将此粘贴到答案部分,提交,然后将答案标记为已接受,以表明问题已解决吗?是的,这有助于我们挖掘未回答的问题,知道问题已解决。