Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Zend Engine Extension static method call
    text
    copied!<p>I am writing a PHP extension. From the C code I try to invoke a static method in PHP code. </p> <p>The PHP-method looks like this:</p> <pre><code>&lt;?php class Model { static method GetModelById($id) { ... } } ?&gt; </code></pre> <p>The call in C looks like this:</p> <pre><code>if( call_user_function_ex( &amp;((*ce)-&gt;function_table), NULL, &amp;fname, &amp;retval_ptr, 1, func_params, 0, NULL TSRMLS_CC ) == SUCCESS ){ // do some stuff here ... } </code></pre> <p>... 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.</p> <p>I also tried <code>zend_call_method</code> with no success in either version.</p> <p>Can anyone give a tip for me? How would you call a static method from C?</p> <p>Thanks in advance!</p> <p><strong>Edit</strong></p> <p>Sorry guys, I got it working via <code>zend_call_method</code> like so:</p> <pre><code>if( zend_call_method( NULL, *ce, NULL, "getmodelbyid", strlen("getmodelbyid"), &amp;retval_ptr, 1, p1, NULL TSRMLS_CC ) == FAILURE) { php_printf("gosh!"); } else { php_printf("yep!"); } </code></pre> <p>... so I learned:</p> <ol> <li>Function names must always be in lowercase</li> <li>You better have a look at PHP's source code when it comes to string lengths (<code>zend_call_method</code> adds +1 internally).</li> </ol> <p>Although I am new to C, I think the PHP code base is over-compilcated in many ways!</p> <p>Hope this helps someone else!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload