The content is php5.6.14 for example.
From an example of encapsulating uniqid.
/*{ {{wrapper of uniqid*/php_function (FOX) {
#1. Zval*prefix, *More = NULL; zval function,*params[2] = {0}; //#2. if(Zend_parse_parameters (Zend_num_args () TSRMLS_CC, "z|z" , &prefix, &more) = =FAILURE) { Return_false; } params[0] =prefix; if(more) {params[1] =More ; } //#3.Zval_string (&function,"uniqid",0);
//#4. if(Call_user_function (EG (function_table), NULL,&function, Return_value, Zend_num_args (),paramsTSRMLS_CC) = =FAILURE) { if(return_value) {zval_dtor (return_value); } zend_error (E_warning,"%s () calling%s () failed.", Get_active_function_name (Tsrmls_c), z_strval (function)); Return_false; } return_string (Z_strval_p (return_value),0);}/* }}} */
#1.
Zval The default is non-null, do not arbitrarily assign the declared Zval null, unless you know what you are doing, for example, to determine whether there is a reference;
If you want to use the default value farwish for optional parameters, you can do the following (not for the previous example):
if (more = = NULL) { make_std_zval (more) ; " Farwish " ; = strlen ("farwish"); = is_string;} params [1] = more;
Also do not forget the call_user_function in the number of parameters can no longer use Zend_num_args (), write a fixed value of 2 on it.
#2.
The received parameter type must be wrapped in double quotation marks, in order to avoid other places also encountered this error, it is best to use double quotation marks after unification.
If you receive a parameter with a char *name type, don't forget to have a uint *len followed by it.
#3. #4.
If the beginning of the declaration is Zval *function, and zval_string assignment and call_user_function calls are passed function, compile can pass, but the use will segmentaion fault; test proves that zval_s TRING The first parameter must point to the address of the zval, not the simple zval *, because the macro does zval *__z = (z) Such a thing, if z is already a pointer, then the value is wrong.
Thats all.
Development Documentation: Https://github.com/farwish/php-core-hack
Link:http://www.cnblogs.com/farwish/p/5635429.html
@ Black eyed poet <www.farwish.com>
Recommendations for the use of packaged business and call_user_function in [PHP-SRC] Extensions