2009-03-24 17 views

Respuesta

6

Editar 2011-09-13: La forma correcta de hacer esto es utilizar la familia ZEND_BEGIN_ARG_INFO() de macros - ver Extending and Embedding PHP chapter 6 (Sara Golemon, Developer's Library).

Esta función de ejemplo toma un argumento de cadena por valor (debido a la llamada ZEND_ARG_PASS_INFO(0)) y todos los demás después por referencia (debido a que el segundo argumento para ZEND_BEGIN_ARG_INFO es 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); 
} 

Antes de añadir la memoria convert_to_null que se filtrara en cada llamada (no tengo si esto es necesario después de la adición de ZENG_ARG_INFO() llamadas).

+0

¡Gracias, esto me ayudó mucho! :) – hek2mgl

Cuestiones relacionadas