Abstract: The php version read here is PHP-7.1.0 RC3, and the platform for reading the code is linux. Go back to the zend_eval_stringlZEND_API that we read before int zend_eval_stringl(char *str, size_t str_len, zval *retval_ptr, char *string_name) /* {{ { */ { ... new_o ...
The php version read here is PHP-7.1.0 RC3, and the platform for reading the code is linux
Go back to the zend_eval_stringl we looked at before
01 ZEND_API int zend_eval_stringl(char *str, size_t str_len, zval *retval_ptr, char *string_name) /* {{{ */ 02 { 03 ... 04 new_op_array = zend_compile_string(&pv, string_name); // 这个是把php代码编译成为opcode的过程 05 ... 06 zend_execute(new_op_array, &local_retval); // 这个是具体的执行过程,执行opcode,把结果存储到local_retval中 07 ... 08 retval = SUCCESS; 09 return retval; 10 }
The zend_execute here performs two steps , the first step is the process of compiling and parsing php into opcode, we will look at this first.
zend_compile_string
zend_compile_string function can be traced to compile_string
01 // 将一个字符串解析成为op_array 02 zend_op_array *compile_string(zval *source_string, char *filename) 03 { 04 zend_lex_state original_lex_state; 05 zend_op_array *op_array = NULL; 06 zval tmp; 07 08 // 如果传进来要解析的字符为空,则返回null 09 if (Z_STRLEN_P(source_string)==0) { 10 return NULL; 11 } 12 13 ZVAL_DUP(&tmp, source_string); // 复制source_string到zval中 14 convert_to_string(&tmp); // 如果不是字符类型就转换为字符类型 15 source_string = &tmp; 16 17 zend_save_lexical_state(&original_lex_state); // 保存lex上下文 18 if (zend_prepare_string_for_scanning(source_string, filename) == SUCCESS) { // 做编译前的准备 19 BEGIN(ST_IN_SCRIPTING); // 设置状态为正在编译 20 op_array = zend_compile(ZEND_EVAL_CODE); // 进行编译,并把生成结果放在op_array中 21 } 22 23 zend_restore_lexical_state(&original_lex_state); // 恢复lex上下文 24 zval_dtor(&tmp); // 释放tmp 25 26 return op_array; 27 }
The core one is zend_compile. Here are a few points to look at:
1 To do type conversion, refer to convert_to_string. This function is to convert any type of value into the string type of zval.
2 zval_dtor, this function can recycle any zval variable. perfectly worked.
3 ZVAL_DUP is for copying. The difference between it and ZVAL_COPY is whether to increase the reference count of gc.
The above is the content of PHP kernel analysis (8) - zend_compile. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor