KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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: Function names must always be in lowercase 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!
Tags (comma-separated)
Save Edits
Cancel