Php-echo principle

Source: Internet
Author: User

1. Grammatical analysis

unticked_statement:| T_echo echo_expr_list';'; Echo_expr_list:echo_expr_list','Expr {Zend_do_echo (&$3tsrmls_cc); }    | Expr {Zend_do_echo (&$1tsrmls_cc); };expr:r_variable {$$= $1; } | expr_without_variable {$$ = $1; }; r_variable:variable {zend_do_end_variable_parse (&$1, Bp_var_r,0TSRMLS_CC); $$ = $1; }; Variable:| base_variable_with_function_calls {$$ = $1; }; base_variable_with_function_calls:base_variable {$$= $1; } ; Reference_variable:| compound_variable {zend_do_begin_variable_parse (Tsrmls_c); Fetch_simple_variable (&$$, &$1,1tsrmls_cc); };compound_variable:t_variable {$$= $1; } |'$' '{'Expr'}'{ $$ = $3; };

2. Compile Build opcode

void Zend_do_echo (const/**/{    *opline = Get_next_op ( CG (Active_op_array) tsrmls_cc);    Opline->opcode = Zend_echo;    Set_node (opline-OP1, ARG);    Set_unused (Opline-op2);}

3. Execute the opcode that have been generated

Static int Zend_fastcall  Zend_echo_spec_cv_handler (Zend_opcode_handler_args) {    use_opline    *z;    Save_opline ();     = _get_zval_ptr_cv_bp_var_r (Ex_cvs (), Opline->op1.  var  tsrmls_cc); //This z is already a    value.  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 ();}

StaticZend_always_inline zval *_get_zval_ptr_cv_bp_var_r (zval ***cvs, Zend_uintvartsrmls_dc) {Zvalptr = &CV (var); //eg (Active_op_array). Vars[key] The result is a zend_compile_variable, where key is the variable var of znod_op, which is a number that can be understood as the first variable, and finally in the EG (active_ sysbole_table), and put the data in Ex (CVS) [key] if(Unexpected (*ptr = =NULL)) {        return*_get_zval_cv_lookup_bp_var_r (PTR,vartsrmls_cc); }    return**ptr;}StaticZend_never_inline zval **_get_zval_cv_lookup_bp_var_r (zval ***ptr, Zend_uintvartsrmls_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_apiintZend_print_variable (Zval *var) {    returnZend_print_zval (var,0);} Zend_apiintZend_print_zval (Zval *expr,intIndent/* {{{ */{    returnzend_print_zval_ex (zend_write, expr, indent);} Zend_apiintZEND_PRINT_ZVAL_EX (zend_write_func_t write_func, Zval *expr,intIndent/* {{{ */{zval expr_copy; intuse_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); }    returnz_strlen_p (expr);}intPhp_module_startup (sapi_module_struct *sf, Zend_module_entry *additional_modules,UINTnum_additional_modules)    {zend_utility_functions Zuf;    Zend_utility_values Zuv; intretval = 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 intPhp_output_wrapper (Const Char*STR,UINTstr_length)    {Tsrmls_fetch (); returnphp_output_write (str, str_length tsrmls_cc);} PhpapiintPhp_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; }    returnphp_output_direct (str, len);}Static int(*php_output_direct) (Const Char*str, size_t str_len) =Php_output_stderr;Static intPhp_output_stderr (Const Char*str, size_t Str_len) { fwrite (str, 1, Str_len, stderr); You know that echo is output with fwrite./* Seehttp://support.microsoft.com/kb/190351 */#ifdef php_win32 fflush (stderr);#endif    returnStr_len;}

Reference: http://wenku.baidu.com/view/b7d2d4335a8102d276a22fb1.html

Php-echo principle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.