2009-03-24 26 views

risposta

6

Edit 2011-09-13: Il modo corretto per farlo è quello di utilizzare la ZEND_BEGIN_ARG_INFO() famiglia di macro - vedi Extending and Embedding PHP chapter 6 (Sara Golemon, Developer's Library).

Questa funzione di esempio accetta un argomento stringa per valore (a causa della chiamata ZEND_ARG_PASS_INFO(0)) e tutti gli altri dopo quello per riferimento (a causa del secondo argomento a ZEND_BEGIN_ARG_INFO è 1).

const int pass_rest_by_reference = 1; 
const int pass_arg_by_reference = 0; 

ZEND_BEGIN_ARG_INFO(AllButFirstArgByReference, pass_rest_by_reference) 
    ZEND_ARG_PASS_INFO(pass_arg_by_reference) 
ZEND_END_ARG_INFO() 

zend_function_entry my_functions[] = { 
    PHP_FE(TestPassRef, AllButFirstArgByReference) 
}; 

PHP_FUNCTION(TestPassRef) 
{ 
    char *someString = NULL; 
    int lengthString = 0; 
    zval *pZVal = NULL; 

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &someString, &lengthString, &pZVal) == FAILURE) 
    { 
     return; 
    } 

    convert_to_null(pZVal); // Destroys the value that was passed in 

    ZVAL_STRING(pZVal, "some string that will replace the input", 1); 
} 

Prima di aggiungere memoria convert_to_null sarebbe perdere su ogni chiamata (non ho non è se ciò sia necessario dopo l'aggiunta ZENG_ARG_INFO() chiamate).

+0

Grazie, questo mi ha aiutato molto! :) – hek2mgl

Problemi correlati