php сбой функции zend с нечетным числом параметров - PullRequest
0 голосов
/ 09 июля 2020

Ниже приводится функция zend, которую я использую. Если я использую нечетное количество параметров, происходит сбой. И он работает, когда у него четное количество аргументов.

Может ли кто-нибудь помочь мне найти причину root?

/*Step 1: declaration of functions to be exported */

ZEND_FUNCTION(APIRequest);


ZEND_BEGIN_ARG_INFO(get_simple, 1)
ZEND_ARG_PASS_INFO(1) 
ZEND_END_ARG_INFO()


/*Step 2: compiled function list so Zend knows what's in this module */

zend_function_entry API_functions[] =
{
    ZEND_FE(APIRequest, get_simple)
   {
NULL, NULL, NULL
}
};


/*Step 3: compiled module information */
zend_module_entry API_module_entry = {
    STANDARD_MODULE_HEADER,
    //the extension name
    "API",
    //the functions exported
    API_functions,
    NULL,   //Module startup function
    NULL,   //Module shutdown function
    NULL,   //request startup function
    NULL,   //request shutdown function
    NULL,   //info function(called by phpinfo()     
    NO_VERSION_YET,//version
    STANDARD_MODULE_PROPERTIES
};

/*Step 4: implement standard "stub" routine to introduce ourselves to Zend load module dynamically*/
ZEND_GET_MODULE(API)


/*Step 5: Implementation of Functions */
ZEND_FUNCTION(APIRequest)
{

    int iErrorCode = 0;
    char *debug1, *debug2;
    int iDebug1Len, iDebug2Len;

    bool bSecure;

    zval *sResponse;


    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/|ss",
        &sResponse,
        &debug1, &iDebug1Len,
        &debug2, &iDebug2Len
    ) == FAILURE)
    {
        convert_to_null(sResponse);
        ZVAL_STRING(sResponse, "Error. Parameter issue", 1);

        iErrorCode = 4;
        RETURN_LONG(iErrorCode);
    }

    *(debug1 + iDebug1Len) = 0;
    *(debug2 + iDebug2Len) = 0;

    string sResultMsg = "Return value set";

    convert_to_null(sResponse);
    ZVAL_STRING(sResponse, (char *)sResultMsg.c_str(), 1);

    RETURN_LONG(iErrorCode);
}

// PHP function definition END

PHP код для вызова

Успех case:

<?php

$retVal = APIRequest($sResponseValue, "");
error_log($sResponseValue);

?>

Случай отказа 1

<?php

$retVal = APIRequest($sResponseValue);
error_log($sResponseValue);

?>

Случай отказа 2

<?php

$retVal = APIRequest($sResponseValue, "", "");
error_log($sResponseValue);

?>
...