📄 basic_functions.c
字号:
} convert_to_long_ex(erropt); opt_err = Z_LVAL_PP(erropt); convert_to_string_ex(option); opt = Z_STRVAL_PP(option); break; case 4: if (zend_get_parameters_ex (4, &string, &erropt, &option, &emailhead) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid arguments"); RETURN_FALSE; } break; default: WRONG_PARAM_COUNT; } convert_to_string_ex(string); message = Z_STRVAL_PP(string); if (erropt != NULL) { convert_to_long_ex(erropt); opt_err = Z_LVAL_PP(erropt); } if (option != NULL) { convert_to_string_ex(option); opt = Z_STRVAL_PP(option); } if (emailhead != NULL) { convert_to_string_ex(emailhead); headers = Z_STRVAL_PP(emailhead); } if (_php_error_log(opt_err, message, opt, headers TSRMLS_CC) == FAILURE) { RETURN_FALSE; } RETURN_TRUE;}/* }}} */PHPAPI int _php_error_log(int opt_err, char *message, char *opt, char *headers TSRMLS_DC){ php_stream *stream = NULL; switch (opt_err) { case 1: /*send an email */ {#if HAVE_SENDMAIL if (!php_mail(opt, "PHP error_log message", message, headers, NULL TSRMLS_CC)) { return FAILURE; }#else php_error_docref(NULL TSRMLS_CC, E_WARNING, "Mail option not available!"); return FAILURE;#endif } break; case 2: /*send to an address */ php_error_docref(NULL TSRMLS_CC, E_WARNING, "TCP/IP option not available!"); return FAILURE; break; case 3: /*save to a file */ stream = php_stream_open_wrapper(opt, "a", IGNORE_URL_WIN | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); if (!stream) return FAILURE; php_stream_write(stream, message, strlen(message)); php_stream_close(stream); break; default: php_log_err(message TSRMLS_CC); break; } return SUCCESS;}/* {{{ proto mixed call_user_func(string function_name [, mixed parmeter] [, mixed ...]) Call a user function which is the first parameter */PHP_FUNCTION(call_user_func){ zval ***params; zval *retval_ptr; char *name; int argc = ZEND_NUM_ARGS(); if (argc < 1) { WRONG_PARAM_COUNT; } params = safe_emalloc(sizeof(zval **), argc, 0); if (zend_get_parameters_array_ex(argc, params) == FAILURE) { efree(params); RETURN_FALSE; } if (Z_TYPE_PP(params[0]) != IS_STRING && Z_TYPE_PP(params[0]) != IS_ARRAY) { SEPARATE_ZVAL(params[0]); convert_to_string_ex(params[0]); } if (!zend_is_callable(*params[0], 0, &name)) { php_error_docref1(NULL TSRMLS_CC, name, E_WARNING, "First argument is expected to be a valid callback"); efree(name); efree(params); RETURN_NULL(); } if (call_user_function_ex(EG(function_table), NULL, *params[0], &retval_ptr, argc-1, params+1, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) { COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); } else { if (argc > 1) { SEPARATE_ZVAL(params[1]); convert_to_string_ex(params[1]); if (argc > 2) { SEPARATE_ZVAL(params[2]); convert_to_string_ex(params[2]); php_error_docref1(NULL TSRMLS_CC, name, E_WARNING, "Unable to call %s(%s,%s)", name, Z_STRVAL_PP(params[1]), Z_STRVAL_PP(params[2])); } else { php_error_docref1(NULL TSRMLS_CC, name, E_WARNING, "Unable to call %s(%s)", name, Z_STRVAL_PP(params[1])); } } else { php_error_docref1(NULL TSRMLS_CC, name, E_WARNING, "Unable to call %s()", name); } } efree(name); efree(params);}/* }}} *//* {{{ proto mixed call_user_func_array(string function_name, array parameters) Call a user function which is the first parameter with the arguments contained in array */PHP_FUNCTION(call_user_func_array){ zval ***func_params, **func, **params; zval *retval_ptr; HashTable *func_params_ht; char *name; int count; int current = 0; if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &func, ¶ms) == FAILURE) { WRONG_PARAM_COUNT; } SEPARATE_ZVAL(params); convert_to_array_ex(params); if (Z_TYPE_PP(func) != IS_STRING && Z_TYPE_PP(func) != IS_ARRAY) { SEPARATE_ZVAL(func); convert_to_string_ex(func); } if (!zend_is_callable(*func, 0, &name)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "First argumented is expected to be a valid callback, '%s' was given", name); efree(name); RETURN_NULL(); } func_params_ht = Z_ARRVAL_PP(params); count = zend_hash_num_elements(func_params_ht); func_params = safe_emalloc(sizeof(zval **), count, 0); for (zend_hash_internal_pointer_reset(func_params_ht); zend_hash_get_current_data(func_params_ht, (void **) &func_params[current]) == SUCCESS; zend_hash_move_forward(func_params_ht) ) { current++; } if (call_user_function_ex(EG(function_table), NULL, *func, &retval_ptr, count, func_params, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) { COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s()", name); } efree(name); efree(func_params);}/* }}} */#define _CUM_DEPREC "This function is deprecated, use the call_user_func variety with the array(&$obj, \"method\") syntax instead"/* {{{ proto mixed call_user_method(string method_name, mixed object [, mixed parameter] [, mixed ...]) Call a user method on a specific object or class */PHP_FUNCTION(call_user_method){ zval ***params; zval *retval_ptr; int arg_count = ZEND_NUM_ARGS(); php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s", _CUM_DEPREC); if (arg_count < 2) { WRONG_PARAM_COUNT; } params = (zval ***) safe_emalloc(sizeof(zval **), arg_count, 0); if (zend_get_parameters_array_ex(arg_count, params) == FAILURE) { efree(params); RETURN_FALSE; } if (Z_TYPE_PP(params[1]) != IS_OBJECT && Z_TYPE_PP(params[1]) != IS_STRING) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Second argument is not an object or class name"); efree(params); RETURN_FALSE; } SEPARATE_ZVAL(params[0]); convert_to_string(*params[0]); if (call_user_function_ex(EG(function_table), params[1], *params[0], &retval_ptr, arg_count-2, params+2, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) { COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s()", Z_STRVAL_PP(params[0])); } efree(params);}/* }}} *//* {{{ proto mixed call_user_method_array(string method_name, mixed object, array params) Call a user method on a specific object or class using a parameter array */PHP_FUNCTION(call_user_method_array){ zval **method_name, **obj, **params, ***method_args = NULL, *retval_ptr; HashTable *params_ar; int num_elems, element = 0; php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s", _CUM_DEPREC); if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &method_name, &obj, ¶ms) == FAILURE) { WRONG_PARAM_COUNT; } if (Z_TYPE_PP(obj) != IS_OBJECT && Z_TYPE_PP(obj) != IS_STRING) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Second argument is not an object or class name"); RETURN_FALSE; } SEPARATE_ZVAL(method_name); SEPARATE_ZVAL(params); convert_to_string_ex(method_name); convert_to_array_ex(params); params_ar = HASH_OF(*params); num_elems = zend_hash_num_elements(params_ar); method_args = (zval ***) safe_emalloc(sizeof(zval **), num_elems, 0); for (zend_hash_internal_pointer_reset(params_ar); zend_hash_get_current_data(params_ar, (void **) &(method_args[element])) == SUCCESS; zend_hash_move_forward(params_ar) ) { element++; } if (call_user_function_ex(EG(function_table), obj, *method_name, &retval_ptr, num_elems, method_args, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) { COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s()", Z_STRVAL_PP(method_name)); } efree(method_args);}/* }}} */void user_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);}void user_tick_function_dtor(user_tick_function_entry *tick_function_entry){ int i; for (i = 0; i < tick_function_entry->arg_count; i++) { zval_ptr_dtor(&tick_function_entry->arguments[i]); } efree(tick_function_entry->arguments);}static int user_shutdown_function_call(php_shutdown_function_entry *shutdown_function_entry TSRMLS_DC){ zval retval; char *function_name = NULL; if (!zend_is_callable(shutdown_function_entry->arguments[0], 0, &function_name)) { php_error(E_WARNING, "(Registered shutdown functions) Unable to call %s() - function does not exist", function_name); } else if (call_user_function(EG(function_table), NULL, shutdown_function_entry->arguments[0], &retval, shutdown_function_entry->arg_count - 1, shutdown_function_entry->arguments + 1 TSRMLS_CC ) == SUCCESS) { zval_dtor(&retval); } if (function_name) { efree(function_name); } return 0;}static void user_tick_function_call(user_tick_function_entry *tick_fe TSRMLS_DC){ zval retval; zval *function = tick_fe->arguments[0]; /* Prevent reentrant calls to the same user ticks function */ if (! tick_fe->calling) { tick_fe->calling = 1; if (call_user_function( EG(function_table), NULL, function, &retval, tick_fe->arg_count - 1, tick_fe->arguments+1 TSRMLS_CC) == SUCCESS) { zval_dtor(&retval); } else { zval **obj, **method; if (Z_TYPE_P(function) == IS_STRING) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s() - function does not exist", Z_STRVAL_P(function)); } else if ( Z_TYPE_P(function) == IS_ARRAY && zend_hash_index_find(Z_ARRVAL_P(function), 0, (void **) &obj) == SUCCESS && zend_hash_index_find(Z_ARRVAL_P(function), 1, (void **) &method) == SUCCESS && Z_TYPE_PP(obj) == IS_OBJECT && Z_TYPE_PP(method) == IS_STRING ) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s::%s() - function does not exist", Z_OBJCE_PP(obj)->name, Z_STRVAL_PP(method)); } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call tick function"); } } tick_fe->calling = 0; }}static void run_user_tick_functions(int tick_count){ TSRMLS_FETCH(); zend_llist_apply(BG(user_tick_functions), (llist_apply_func_t) user_tick_function_call TSRMLS_CC);}static int user_tick_function_compare(user_tick_function_entry * tick_fe1, user_tick_function_entry * tick_fe2){ zval *func1 = tick_fe1->arguments[0]; zval *func2 = tick_fe2->arguments[0]; TSRMLS_FETCH(); if (Z_TYPE_P(func1) == IS_STRING && Z_TYPE_P(func2) == IS_STRING) { return (zend_binary_zval_strcmp(func1, func2) == 0); } else if (Z_TYPE_P(func1) == IS_ARRAY && Z_TYPE_P(func2) == IS_ARRAY) { zval result; zend_compare_arrays(&result, func1, func2 TSRMLS_CC); return (Z_LVAL(result) == 0); } else { return 0; }}void php_call_shutdown_functions(TSRMLS_D){ if (BG(user_shutdown_function_names)) zend_try { zend_hash_apply(BG(user_shutdown_function_names), (apply_func_t) user_shutdown_function_call TSRMLS_CC); memcpy(&EG(bailout), &orig_bailout, sizeof(jmp_buf)); php_free_shutdown_functions(TSRMLS_C); } zend_end_try();}void php_free_shutdown_functions(TSRMLS_D){ if (BG(user_shutdown_function_names)) zend_try { zend_hash_destroy(BG(user_shutdown_function_names)); FREE_HASHTABLE(BG(user_shutdown_function_names)); BG(user_shutdown_function_names) = NULL; } zend_end_try();}/* {{{ proto void register_shutdown_function(string function_name) Register a user-level function to be called on request termination */PHP_FUNCTION(register_shutdown_function){ php_shutdown_function_entry shutdown_function_entry; char *function_name = NULL; int i; shutdown_function_entry.arg_count = ZEND_NUM_ARGS(); if (shutdown_function_entry.arg_count < 1) { WRONG_PARAM_COUNT; } shutdown_function_entry.arguments = (zval **) safe_emalloc(sizeof(zval *), shutdown_function_entry.arg_count, 0); if (zend_get_parameters_array(ht, shutdown_function_entry.arg_count, shutdown_function_entry.arguments) == FAILURE) { efree(shutdown_function_entry.arguments); RETURN_FALSE; } /* Prevent entering of anything but valid callback (syntax check only!) */ if (!zend_is_callable(shutdown_function_entry.arguments[0], 1, &function_name)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid shutdown callback '%s' passed", function_name); efree(shutdown_function_entry.arguments); RETVAL_FALSE; } else { 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 *)) user_shutdown_function_dtor, 0); } for (i = 0; i < shutdown_function_entry.arg_count; i++) { shutdown_function_entry.arguments[i]->refcount++; } zend_hash_next_index_insert(BG(user_shutdown_function_names), &shutdown_function_entry, sizeof(php_shutdown_function_entry), NULL); } if (function_name) { efree(function_name); }}/* }}} */ZEND_API void php_get_highlight_struct(zend_syntax_highlighter_ini *syntax_highlighter_ini){ syntax_highlighter_ini->highlight_comment = INI_STR("highlight.comment"); syntax_highlighter_ini->highlight_default = INI_STR("highlight.default")
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -