Chenglu
Chenglu

Reputation: 1997

php extension call_user_function segment fault

my code is like the follows:

ZEND_FUNCTION(mysql_query1)
{
    zval *args[1];
    MAKE_STD_ZVAL(args[0]);
    ZVAL_STRING(args[0], "hehe", 1); 
    zval *fname = NULL;
    ZVAL_STRING(fname, "print", 0); 

    zval *retval = NULL;

    if (call_user_function(EG(function_table), NULL, fname, retval, 1, args TSRMLS_CC) == SUCCESS) {
    }   
}

As i tested , it is cored when executing the call_user_function, I just want to invoke the print() function of php in my extension, but why does this cause a segment?

any ideas?

Upvotes: 0

Views: 388

Answers (1)

NikiC
NikiC

Reputation: 101906

print is not a function, but a language construct. If you want to print a zval use zend_print_variable(zval).

Alternatively you may also be interested in PHPWRITE(str, len) and php_printf(format, ...).

The reason your code segfaults is not related to this: You did not allocate the fname zval.

Upvotes: 1

Related Questions