Answer the question
In order to leave comments, you need to log in
PHP extension and php callback?
Hi
I am writing a test module for PHP
It has a class Test1 it has an addCallback method and also an event on set ( handler set )
addCallback method:
PHP_METHOD(Test1, addCallback)
{
Test1_Extra *ExThis = (Test1_Extra*) zend_object_store_get_object(getThis() TSRMLS_CC);
// запоминаем callback
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f", &(ExThis->callback), &(ExThis->callback_cache)) == FAILURE) {
return;
}
// здесь запускаем callback для теста
zend_fcall_info_call(&(ExThis->callback), &(ExThis->callback_cache), NULL, NULL TSRMLS_CC);
}
void Test1_object_set(zval **pzobject, zval *value TSRMLS_DC)
{
Test1_Extra *ExThis = (Test1_Extra*) zend_object_store_get_object(*pzobject TSRMLS_CC);
zend_fcall_info_call(&(ExThis->callback), &(ExThis->callback_cache), NULL, NULL TSRMLS_CC);
}
<?php
function test_callback() {
echo 'run'.PHP_EOL;
}
$test = new Test1;
$test->addCallback('test_callback');
$test = 'dd'; // здесь срабатывает Test1_object_set
run<br/>
Segmentation fault<br/>
static void Test1_object_set(zval **pzobject, zval *value TSRMLS_DC)
{
Test1_Extra *ExThis = (Test1_Extra*) zend_object_store_get_object(*pzobject TSRMLS_CC);
zval *fname;
zend_fcall_info fci;
zend_fcall_info_cache fcc;
MAKE_STD_ZVAL(fname);
ZVAL_STRINGL(fname, "test_callback", 3, 1);
zend_fcall_info_init(fname, 0, &fci, &fcc, NULL, NULL TSRMLS_CC);
// выполняем вручную функцию test_callback
zend_fcall_info_call(&fci, &fcc, NULL, NULL TSRMLS_CC);
zend_fcall_info_call(&(ExThis->callback), &(ExThis->callback_cache), NULL, NULL TSRMLS_CC);
}
run<br/>
run<br/>
run<br/>
zend_fcall_info_init(fname, 0, &fci, &fcc, NULL, NULL TSRMLS_CC);
zend_fcall_info_call(&(ExThis->callback), &(ExThis->callback_cache), NULL, NULL TSRMLS_CC);
zval *fname = ExThis->callback.function_name;
char *cfname = Z_STRVAL_P(fname);
php_printf("fname: %s\n", "test msg");
php_printf("fname: %s\n", cfname);
fname: test msg<br/>
Segmentation fault<br/>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question