日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php-echo原理

發布時間:2025/5/22 php 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php-echo原理 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.語法分析

?

unticked_statement: | T_ECHO echo_expr_list ';' ; echo_expr_list:echo_expr_list ',' expr { zend_do_echo(&$3 TSRMLS_CC); }| expr { zend_do_echo(&$1 TSRMLS_CC); } ; expr:r_variable { $$ = $1; }| expr_without_variable { $$ = $1; } ; r_variable:variable { zend_do_end_variable_parse(&$1, BP_VAR_R, 0 TSRMLS_CC); $$ = $1; } ; variable:base_variable_with_function_calls ; base_variable_with_function_calls:base_variable { $$ = $1; } ; base_variable:reference_variable { $$ = $1; $$.EA = ZEND_PARSED_VARIABLE; } ; reference_variable:| compound_variable { zend_do_begin_variable_parse(TSRMLS_C); fetch_simple_variable(&$$, &$1, 1 TSRMLS_CC); } ;compound_variable:T_VARIABLE { $$ = $1; }| '$' '{' expr '}' { $$ = $3; } ;| compound_variable { zend_do_begin_variable_parse(TSRMLS_C); fetch_simple_variable(&$$, &$1, 1 TSRMLS_CC); } ; compound_variable:T_VARIABLE { $$ = $1; }

?

2.編譯生成opcode

void zend_do_echo(const znode *arg TSRMLS_DC) /* {{{ */ {zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);opline->opcode = ZEND_ECHO;SET_NODE(opline->op1, arg);SET_UNUSED(opline->op2); }

?

3.執行已經生成的opcode

static int ZEND_FASTCALL ZEND_ECHO_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS) {USE_OPLINEzval *z;SAVE_OPLINE();z = _get_zval_ptr_cv_BP_VAR_R(EX_CVs(), opline->op1.var TSRMLS_CC); //這個z已經是值了if (IS_CV == IS_TMP_VAR && Z_TYPE_P(z) == IS_OBJECT) {INIT_PZVAL(z);}zend_print_variable(z);CHECK_EXCEPTION();ZEND_VM_NEXT_OPCODE(); }

?

static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_R(zval ***CVs, zend_uint var TSRMLS_DC) {zval ***ptr = &CV(var); //EG(active_op_array).vars[key]該結果是個zend_compile_variable ,其中key為znod_op的變量var,是個數字,可理解為第幾個變量,最終在EG(active_sysbole_table)中取出數據,放到EX(CVs)[key]中if (UNEXPECTED(*ptr == NULL)) {return *_get_zval_cv_lookup_BP_VAR_R(ptr, var TSRMLS_CC);}return **ptr; }static zend_never_inline zval **_get_zval_cv_lookup_BP_VAR_R(zval ***ptr, zend_uint var TSRMLS_DC) {zend_compiled_variable *cv = &CV_DEF_OF(var);if (!EG(active_symbol_table) ||zend_hash_quick_find(EG(active_symbol_table), cv->name, cv->name_len+1, cv->hash_value, (void **)ptr)==FAILURE) {zend_error(E_NOTICE, "Undefined variable: %s", cv->name);return &EG(uninitialized_zval_ptr);}return *ptr; }

?

ZEND_API int zend_print_variable(zval *var) {return zend_print_zval(var, 0); }ZEND_API int zend_print_zval(zval *expr, int indent) /* {{{ */ {return zend_print_zval_ex(zend_write, expr, indent); }ZEND_API int zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int indent) /* {{{ */ {zval expr_copy;int use_copy;zend_make_printable_zval(expr, &expr_copy, &use_copy);if (use_copy) {expr = &expr_copy;}if (Z_STRLEN_P(expr) == 0) { /* optimize away empty strings */if (use_copy) {zval_dtor(expr);}return 0;}write_func(Z_STRVAL_P(expr), Z_STRLEN_P(expr));if (use_copy) {zval_dtor(expr);}return Z_STRLEN_P(expr); }int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_modules, uint num_additional_modules) {zend_utility_functions zuf;zend_utility_values zuv;int retval = SUCCESS, module_number=0; /* for REGISTER_INI_ENTRIES() */。。。。。。。。。。。。。。sapi_module = *sf;php_output_startup();zuf.error_function = php_error_cb;zuf.printf_function = php_printf;zuf.write_function = php_output_wrapper;zuf.fopen_function = php_fopen_wrapper_for_zend;zuf.message_handler = php_message_handler_for_zend;zuf.block_interruptions = sapi_module.block_interruptions;zuf.unblock_interruptions = sapi_module.unblock_interruptions;zuf.get_configuration_directive = php_get_configuration_directive_for_zend;zuf.ticks_function = php_run_ticks;zuf.on_timeout = php_on_timeout;zuf.stream_open_function = php_stream_open_for_zend;zuf.vspprintf_function = vspprintf;zuf.getenv_function = sapi_getenv;zuf.resolve_path_function = php_resolve_path_for_zend;zend_startup(&zuf, NULL TSRMLS_CC);

?

static int php_output_wrapper(const char *str, uint str_length) {TSRMLS_FETCH();return php_output_write(str, str_length TSRMLS_CC); } PHPAPI int php_output_write(const char *str, size_t len TSRMLS_DC) {if (OG(flags) & PHP_OUTPUT_DISABLED) {return 0;}if (OG(flags) & PHP_OUTPUT_ACTIVATED) {php_output_op(PHP_OUTPUT_HANDLER_WRITE, str, len TSRMLS_CC);return (int) len;}return php_output_direct(str, len); } static int (*php_output_direct)(const char *str, size_t str_len) = php_output_stderr;static int php_output_stderr(const char *str, size_t str_len) {fwrite(str, 1, str_len, stderr); //可知道echo 是用fwrite輸出的 /* See http://support.microsoft.com/kb/190351 */ #ifdef PHP_WIN32fflush(stderr); #endifreturn str_len; }

?

?參考:http://wenku.baidu.com/view/b7d2d4335a8102d276a22fb1.html

?

?

轉載于:https://www.cnblogs.com/taek/p/4118838.html

總結

以上是生活随笔為你收集整理的php-echo原理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。