2010-06-29 10 views

उत्तर

9

आप एक एक्सटेंशन लिख सकते हैं और BG(user_shutdown_function_names) पर देख सकते हैं। register_shutdown_function के लिए एक रैपर बनाने के लिए शायद आसान है जो कुछ सरणी में शट डाउन फ़ंक्शंस सहेजता है और इसके बजाय इसे कॉल करता है।

(untested)

#include "ext/standard/basic_functions.h" 
//usual include suspects here 

typedef struct _php_shutdown_function_entry { 
    zval **arguments; 
    int arg_count; 
} php_shutdown_function_entry; 

static void _shutdown_function_dtor(php_shutdown_function_entry *shutdown_function_entry) /* {{{ */ 
{ 
    int i; 

    for (i = 0; i < shutdown_function_entry->arg_count; i++) { 
     zval_ptr_dtor(&shutdown_function_entry->arguments[i]); 
    } 
    efree(shutdown_function_entry->arguments); 
} 

static int _build_shutdown_array(php_shutdown_function_entry *entry, zval *arr TSRMLS_DC) 
{ 
    zval *inner; 
    zval *args; 
    int i; 

    array_init(inner); 
    array_init(args); 
    Z_ADDREF_P(entry->arguments[0]); 
    add_assoc_zval(inner, "callback", entry->arguments[0]); 

    for (i = 1; i < entry->arg_count; i++) { 
     Z_ADDREF_P(entry->arguments[i]); 
     add_next_index_zval(args, entry->arguments[i]); 
    } 
    add_assoc_zval(inner, "arguments", args); 

    add_next_index_zval(arr, inner); 
} 

PHP_FUNCTION(list_shutdown_functions) 
{ 
    if (zend_parse_parameters_none() == FAILURE) 
     return; 

    if (!BG(user_shutdown_function_names)) { 
     ALLOC_HASHTABLE(BG(user_shutdown_function_names)); 
     zend_hash_init(BG(user_shutdown_function_names), 0, NULL, 
      (void (*)(void *)) _shutdown_function_dtor, 0); 
    } 

    array_init(return_value); 

    zend_hash_apply_with_argument(BG(user_shutdown_function_names), 
     (apply_func_arg_t) _build_shutdown_array, return_value TSRMLS_CC); 
} 
+0

वाह, क्या बारे में गहराई से जवाब। अधिकांश समय PHP के पास PHP स्तर पर चीजें करने के लिए पहले से ही एक फ़ंक्शन है, लेकिन इस मामले में यह नहीं है, और फिर भी आप अभी भी समाधान के साथ आए हैं! –

2

स्वयं को ट्रैक रखने के अलावा, नहीं। पंजीकृत फ़ंक्शन नामों की सूची आपकी PHP स्क्रिप्ट से अवगत नहीं है। यदि आप स्वयं PHP को विस्तारित करने के लिए खुले हैं (यह एक आसान काम होगा) तो आर्टेफैक्टो का जवाब देखें।

संबंधित मुद्दे