摘要:這裡閱讀的php版本為PHP-7.1.0 RC3,閱讀程式碼的平台為linuxCGCG是從全域的compiler_global取得屬性值,裡面儲存的就是編譯過程使用到的全域變數。 struct _zend_compiler_globals { zend_stack loop_var_stack; zen ...
這裡閱讀的php版本為PHP-7.1.0 RC3,閱讀程式碼的平台為linux
CG
CG是從全域的儲存值,global就是編譯過程使用到的全域變數。
01 struct _zend_compiler_globals { 02 zend_stack loop_var_stack; 03 04 zend_class_entry *active_class_entry; 05 06 zend_string *compiled_filename; 07 08 int zend_lineno; 09 10 zend_op_array *active_op_array; 11 12 HashTable *function_table; /* function symbol table */ 13 HashTable *class_table; /* class table */ 14 15 HashTable filenames_table; 16 17 HashTable *auto_globals; 18 19 zend_bool parse_error; 20 zend_bool in_compilation; 21 zend_bool short_tags; 22 23 zend_bool unclean_shutdown; 24 25 zend_bool ini_parser_unbuffered_errors; 26 27 zend_llist open_files; 28 29 struct _zend_ini_parser_param *ini_parser_param; 30 31 uint32_t start_lineno; // 执行文件开始执行的行号 32 zend_bool increment_lineno; 33 34 zend_string *doc_comment; 35 uint32_t extra_fn_flags; 36 37 uint32_t compiler_options; /* set of ZEND_COMPILE_* constants */ 38 39 HashTable const_filenames; 40 41 zend_oparray_context context; 42 zend_file_context file_context; 43 44 zend_arena *arena; 45 46 zend_string *empty_string; 47 zend_string *one_char_string[256]; 48 zend_string **known_strings; 49 uint32_t known_strings_count; 50 51 HashTable interned_strings; 52 53 const zend_encoding **script_encoding_list; 54 size_t script_encoding_list_size; 55 zend_bool multibyte; 56 zend_bool detect_unicode; 57 zend_bool encoding_declared; 58 59 zend_ast *ast; 60 zend_arena *ast_arena; 61 62 zend_stack delayed_oplines_stack; 63 64 #ifdef ZTS 65 zval **static_members_table; 66 int last_static_member; 67 #endif 68 };
SG
01 SG是从全局的sapi_global中获取属性值 02 03 // TODO:更新 04 typedef struct _sapi_globals_struct { 05 void *server_context; 06 sapi_request_info request_info; // 请求信息 07 sapi_headers_struct sapi_headers; 08 int64_t read_post_bytes; 09 unsigned char post_read; 10 unsigned char headers_sent; 11 zend_stat_t global_stat; 12 char *default_mimetype; 13 char *default_charset; 14 HashTable *rfc1867_uploaded_files; 15 zend_long post_max_size; 16 int options; 17 zend_bool sapi_started; 18 double global_request_time; 19 HashTable known_post_content_types; 20 zval callback_func; 21 zend_fcall_info_cache fci_cache; 22 } sapi_globals_struct;
EG
EG是從executor_globals中取得變數
01 // TODO: 更新 02 struct _zend_executor_globals { 03 zval uninitialized_zval; 04 zval error_zval; 05 06 /* symbol table cache */ 07 zend_array *symtable_cache[SYMTABLE_CACHE_SIZE]; 08 zend_array **symtable_cache_limit; 09 zend_array **symtable_cache_ptr; 10 11 zend_array symbol_table; /* main symbol table */ 12 13 HashTable included_files; /* files already included */ 14 15 JMP_BUF *bailout; 16 17 int error_reporting; 18 int exit_status; 19 20 HashTable *function_table; /* function symbol table */ 21 HashTable *class_table; /* class table */ 22 HashTable *zend_constants; /* constants table */ 23 24 zval *vm_stack_top; 25 zval *vm_stack_end; 26 zend_vm_stack vm_stack; 27 28 struct _zend_execute_data *current_execute_data; 29 zend_class_entry *fake_scope; /* used to avoid checks accessing properties */ 30 31 zend_long precision; 32 33 int ticks_count; 34 35 HashTable *in_autoload; 36 zend_function *autoload_func; 37 zend_bool full_tables_cleanup; 38 39 /* for extended information support */ 40 zend_bool no_extensions; 41 42 zend_bool vm_interrupt; 43 zend_bool timed_out; 44 zend_long hard_timeout; 45 46 #ifdef ZEND_WIN32 47 OSVERSIONINFOEX windows_version_info; 48 #endif 49 50 HashTable regular_list; 51 HashTable persistent_list; 52 53 int user_error_handler_error_reporting; 54 zval user_error_handler; 55 zval user_exception_handler; 56 zend_stack user_error_handlers_error_reporting; 57 zend_stack user_error_handlers; 58 zend_stack user_exception_handlers; 59 60 zend_error_handling_t error_handling; 61 zend_class_entry *exception_class; 62 63 /* timeout support */ 64 zend_long timeout_seconds; 65 66 int lambda_count; 67 68 HashTable *ini_directives; 69 HashTable *modified_ini_directives; 70 zend_ini_entry *error_reporting_ini_entry; 71 72 zend_objects_store objects_store; 73 zend_object *exception, *prev_exception; 74 const zend_op *opline_before_exception; 75 zend_op exception_op[3]; 76 77 struct _zend_module_entry *current_module; 78 79 zend_bool active; 80 zend_bool valid_symbol_table; 81 82 zend_long assertions; 83 84 uint32_t ht_iterators_count; /* number of allocatd slots */ 85 uint32_t ht_iterators_used; /* number of used slots */ 86 HashTableIterator *ht_iterators; 87 HashTableIterator ht_iterators_slots[16]; 88 89 void *saved_fpu_cw_ptr; 90 #if XPFPA_HAVE_CW 91 XPFPA_CW_DATATYPE saved_fpu_cw; 92 #endif 93 94 zend_function trampoline; 95 zend_op call_trampoline_op; 96 97 void *reserved[ZEND_MAX_RESERVED_RESOURCES]; 98 };
以上是php核心分析(三)-全域變數的內容,更多相關內容請注意PHPHPcnPcn. )!

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境