Is it possible to call PHP_FUNCTION from the extension

Let me elaborate on the title. Consider, for example, PHP_FUNCTION (session_start). Will I be able to call session_start from session_id, which is another PHP_FUNCTION (this is just for illustration not the actual purpose)?

+3
source share
2 answers

OK, yes, but you should avoid it as much as possible. One of the main advantages of writing internal function implementations is that, contrary to what happens in PHP, C function calls are cheap. In addition, calling PHP functions inside C code is relatively painful.

, session_start php_session_start, . , , C, .

, PHP foo, PHP bar, , , ( PHP_FUNCTION) C- of bar. PHP_FUNCTION(foo) PHP_FUNCTION(bar) .

, PHP - call_user_function:

int call_user_function(HashTable *function_table, zval **object_pp,
    zval *function_name, zval *retval_ptr, zend_uint param_count,
    zval *params[] TSRMLS_DC);

call_user_function_ex , .

, (PHP_FUNCTION) . , EG(function_table) , NULL, , .

, . . "Zend_API.h" , zend_fcall_.

, , C.

+6

. session_start(session_id())

, , session_id() , .

0
source

Source: https://habr.com/ru/post/1762575/


All Articles