A brief discussion on PHP source code five: About the creation of array array

不言
Release: 2023-04-01 21:52:02
Original
1551 people have browsed it

This article mainly introduces a brief discussion on PHP source code five: Regarding the creation of array arrays, it has a certain reference value. Now I share it with you. Friends in need can refer to it

Debugging in PHP Use cli to execute PHP files in the environment
Trace the code step by step, because I am not familiar with C and lexical analysis
The PHP files used are as follows:

 <?PHP
 $a = array(1, 2, 3);
 var_dump($a);
Copy after login

The code is simply traced as follows:

 ===>php_execute_script(&file_handle TSRMLS_CC);     //php_cli.c line1130
 ==> retval = (zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 3, prepend_file_p, primary_file, append_file_p) == SUCCESS);    //    main.c 2023行
 ==> EG(active_op_array) = zend_compile_file(file_handle, type TSRMLS_CC);      //    zend.c 1126行
 ==> compiler_result = zendparse(TSRMLS_C);   //    zend_language_scanner.c  3420行==> zend-language_parse.c     2773行==>case 382:     { zend_do_init_array(&(yyval), &(yyvsp[(1) - (1)]), NULL, 0 TSRMLS_CC); }    //    zend_language_parser.c  4689行
    ==>void zend_do_init_array(znode *result, znode *expr, znode *offset, zend_bool is_ref TSRMLS_DC)    //    zend_compile.c 3348行 
 
 ==>case 380:    { zend_do_add_array_element(&(yyval), &(yyvsp[(3) - (3)]), NULL, 0 TSRMLS_CC); }//    zend_language_parser.c  4684行
    ==>void zend_do_add_array_element(znode *result, znode *expr, znode *offset, zend_bool is_ref TSRMLS_DC)    //    zend_compile.c 3371行
Copy after login

During the code tracking process, it was found that when the PHP source code generates a syntax tree, there is no array-related operation when encountering the array and the first number. When the comma after 1 is parsed, the zend_do_init_array function will be called to create Array

The above is just a tracking process. There is no explanation of the code. Due to my limited level, I don’t know much about lexical analysis and syntax analysis.
Another: If there is no carriage return after the last line of code in the PHP program Line break, you will see a bunch of garbled characters when reading the source code file

To be continued...

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please Follow PHP Chinese website!

Related recommendations:

A brief discussion on PHP source code 4: About the count function

A brief discussion on PHP source code 3: About strrchr , strstr, stristr function

A brief discussion on PHP source code 2: About strlen, strtolower, strtoupper, ord, chr function

The above is the detailed content of A brief discussion on PHP source code five: About the creation of array array. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template