开发者

PHP Zend Engine Extension static method call [closed]

开发者 https://www.devze.com 2023-03-24 07:31 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of t开发者_如何学运维he internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

I am writing a PHP extension. From the C code I try to invoke a static method in PHP code.

The PHP-method looks like this:

<?php
class Model {
  static method GetModelById($id) { ... }
}
?>

The call in C looks like this:

if( call_user_function_ex(
      &((*ce)->function_table),
      NULL, &fname, &retval_ptr,
      1, func_params, 0, NULL TSRMLS_CC
    ) == SUCCESS
){
  // do some stuff here ...
}

... where all passed parameters should contain proper values. The strange thing here is: if I compile my extension against php 5.2 the code works fine, if I compile this against php 5.3, the method call fails with no error message.

I also tried zend_call_method with no success in either version.

Can anyone give a tip for me? How would you call a static method from C?

Thanks in advance!

Edit

Sorry guys, I got it working via zend_call_method like so:

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!"); 
}

... so I learned:

  1. Function names must always be in lowercase
  2. You better have a look at PHP's source code when it comes to string lengths (zend_call_method adds +1 internally).

Although I am new to C, I think the PHP code base is over-compilcated in many ways!

Hope this helps someone else!

0

精彩评论

暂无评论...
验证码 换一张
取 消