深入PHP内核之全局变量
在阅读PHP源码的时候,会遇到很多诸如:CG(),EG() ,PG(),FG()这样的宏,如果不了解这些宏的意义,会给理解源码造成很大困难
EG()、这个宏可以用来访问符号表,函数,资源信息和常量
CG() 用来访问核心全局变量
PG() PHP全局变量。我们知道php.ini会映射一个或者多个PHP全局结构。举几个使用这个宏的例子:PG(register_globals), PG(safe_mode), PG(memory_limit)
FG() 文件全局变量。大多数文件I/O或相关的全局变量的数据流都塞进标准扩展出口结构。
申明 Zend/zend_globals_macros.h
typedef struct _zend_compiler_globals zend_compiler_globals;
typedef struct _zend_executor_globals zend_executor_globals; /* Compiler */
#ifdef ZTS
# define CG(v) TSRMG(compiler_globals_id, zend_compiler_globals *, v)
int zendparse(void *compiler_globals);
#else
# define CG(v) (compiler_globals.v)
extern ZEND_API struct _zend_compiler_globals compiler_globals;
int zendparse(void);
#endif /* Executor */
#ifdef ZTS
# define EG(v) TSRMG(executor_globals_id, zend_executor_globals *, v)
#else
# define EG(v) (executor_globals.v)
extern ZEND_API zend_executor_globals executor_globals;
#endif
结构体中的具体定义 Zend/zend_globals.h
/* Define ZTS if you want a thread-safe Zend */
/*#undef ZTS*/ #ifdef ZTS BEGIN_EXTERN_C()
ZEND_API extern int compiler_globals_id;
ZEND_API extern int executor_globals_id;
END_EXTERN_C() #endif
struct _zend_compiler_globals
struct _zend_compiler_globals {
zend_stack bp_stack;
zend_stack switch_cond_stack;
zend_stack foreach_copy_stack;
zend_stack object_stack;
zend_stack declare_stack; zend_class_entry *active_class_entry; /* variables for list() compilation */
zend_llist list_llist;
zend_llist dimension_llist;
zend_stack list_stack; zend_stack function_call_stack; char *compiled_filename; int zend_lineno; zend_op_array *active_op_array; HashTable *function_table; /* function symbol table */
HashTable *class_table; /* class table */ HashTable filenames_table; HashTable *auto_globals; zend_bool parse_error;
zend_bool in_compilation;
zend_bool short_tags;
zend_bool asp_tags; zend_declarables declarables; zend_bool unclean_shutdown; zend_bool ini_parser_unbuffered_errors; zend_llist open_files; long catch_begin; struct _zend_ini_parser_param *ini_parser_param; int interactive; zend_uint start_lineno;
zend_bool increment_lineno; znode implementing_class; zend_uint access_type; char *doc_comment;
zend_uint doc_comment_len; zend_uint compiler_options; /* set of ZEND_COMPILE_* constants */ zval *current_namespace;
HashTable *current_import;
HashTable *current_import_function;
HashTable *current_import_const;
zend_bool in_namespace;
zend_bool has_bracketed_namespaces; HashTable const_filenames; zend_compiler_context context;
zend_stack context_stack; /* interned strings */
char *interned_strings_start;
char *interned_strings_end;
char *interned_strings_top;
char *interned_strings_snapshot_top;
#ifndef ZTS
char *interned_empty_string;
#endif HashTable interned_strings; const zend_encoding **script_encoding_list;
size_t script_encoding_list_size;
zend_bool multibyte;
zend_bool detect_unicode;
zend_bool encoding_declared; #ifdef ZTS
zval ***static_members_table;
int last_static_member;
#endif
};
struct _zend_executor_globals
struct _zend_executor_globals {
zval **return_value_ptr_ptr; zval uninitialized_zval;
zval *uninitialized_zval_ptr; zval error_zval;
zval *error_zval_ptr; /* symbol table cache */
HashTable *symtable_cache[SYMTABLE_CACHE_SIZE];
HashTable **symtable_cache_limit;
HashTable **symtable_cache_ptr; zend_op **opline_ptr; HashTable *active_symbol_table;
HashTable symbol_table; /* main symbol table */ HashTable included_files; /* files already included */ JMP_BUF *bailout; int error_reporting;
int orig_error_reporting;
int exit_status; zend_op_array *active_op_array; HashTable *function_table; /* function symbol table */
HashTable *class_table; /* class table */
HashTable *zend_constants; /* constants table */ zend_class_entry *scope;
zend_class_entry *called_scope; /* Scope of the calling class */ zval *This; long precision; int ticks_count; zend_bool in_execution;
HashTable *in_autoload;
zend_function *autoload_func;
zend_bool full_tables_cleanup; /* for extended information support */
zend_bool no_extensions; #ifdef ZEND_WIN32
zend_bool timed_out;
OSVERSIONINFOEX windows_version_info;
#endif HashTable regular_list;
HashTable persistent_list; zend_vm_stack argument_stack; int user_error_handler_error_reporting;
zval *user_error_handler;
zval *user_exception_handler;
zend_stack user_error_handlers_error_reporting;
zend_ptr_stack user_error_handlers;
zend_ptr_stack user_exception_handlers; zend_error_handling_t error_handling;
zend_class_entry *exception_class; /* timeout support */
int timeout_seconds; int lambda_count; HashTable *ini_directives;
HashTable *modified_ini_directives;
zend_ini_entry *error_reporting_ini_entry; zend_objects_store objects_store;
zval *exception, *prev_exception;
zend_op *opline_before_exception;
zend_op exception_op[3]; struct _zend_execute_data *current_execute_data; struct _zend_module_entry *current_module; zend_property_info std_property_info; zend_bool active; zend_op *start_op; void *saved_fpu_cw_ptr;
#if XPFPA_HAVE_CW
XPFPA_CW_DATATYPE saved_fpu_cw;
#endif void *reserved[ZEND_MAX_RESERVED_RESOURCES];
};
一般EG用的比较多
深入PHP内核之全局变量的更多相关文章
- 24小时学通Linux内核之有关Linux文件系统实现的问题
有时间睡懒觉了,却还是五点多醒了,不过一直躺倒九点多才算起来,昨晚一直在弄飞凌的嵌入式开发板,有些问题没解决,自己电脑系统的问题,虽然Win10发布了,,但我还是好喜欢XP呀,好想回家用用家里的XP来 ...
- 十天学Linux内核之第五天---有关Linux文件系统实现的问题
原文:十天学Linux内核之第五天---有关Linux文件系统实现的问题 有时间睡懒觉了,却还是五点多醒了,不过一直躺倒九点多才算起来,昨晚一直在弄飞凌的嵌入式开发板,有些问题没解决,自己电脑系统的问 ...
- tms320dm6446内核启动分析
关于达芬奇DM6446,里面内部有两个部分,一个是ARM926ejs的核,还有一个是C64+DSP的视频处理核,而我需要关心的重点是arm926ejs的核(bootload和linux内核) 从boo ...
- Win7 x86内核调试与TP反调试的研究
参考 这两天对某P双机调试的学习及成果 ,非常好的一篇分析贴. 本文在Win7 x86下的分析,在虚拟机中以/DEBUG模式启动TP游戏,系统会自动重启. 0x01 内核调试全局变量 根据软件调试 ...
- v79.01 鸿蒙内核源码分析(用户态锁篇) | 如何使用快锁Futex(上) | 百篇博客分析OpenHarmony源码
百篇博客分析|本篇为:(用户态锁篇) | 如何使用快锁Futex(上) 进程通讯相关篇为: v26.08 鸿蒙内核源码分析(自旋锁) | 当立贞节牌坊的好同志 v27.05 鸿蒙内核源码分析(互斥锁) ...
- Compiler Theory(编译原理)、词法/语法/AST/中间代码优化在Webshell检测上的应用
catalog . 引论 . 构建一个编译器的相关科学 . 程序设计语言基础 . 一个简单的语法制导翻译器 . 简单表达式的翻译器(源代码示例) . 词法分析 . 生成中间代码 . 词法分析器的实现 ...
- 2012年7月12 – 腾讯公司 WEB高级应用开发工程师 最新面试题 [转]
笔试(45 minute):(本来是四张纸,被我弄丢了一张!无伤大雅,难度级别不会有出入) 注意:由于时间紧迫和水平有限,难免有不足或错误,请指证,虚心学习! [PHP] 写出PHP中至少5个全局变量 ...
- cp命令的编写——浅谈系统调用
摘要:linux中cp命令的实现,通过这个程序,我们需要了解系统调用耗费时间的方面,同时学会系统调用的错误处理机制. 本文来源:http://blog.csdn.net/trochiluses/art ...
- 文件读写IO
摘要:本文主要总结了以下有关文件读写的IO,系统调用与库函数. 1.初级IO函数:close,creat,lseek,open,write 文件描述符是一个整型数 1.1close 1.2int cr ...
随机推荐
- APACHE 2.2.8+TOMCAT6.0.14配置负载均衡
目标: 使用 apache 和 tomcat 配置一个可以应用的 web 网站,要达到以下要求: 1. Apache 做为 HttpServer ,后面连接多个 tomcat 应用实例,并进行负载均 ...
- 解决sqoop报错:java.lang.OutOfMemoryError: Java heap space
报错栈: -- ::, INFO [main] org.apache.sqoop.mapreduce.db.DBRecordReader: Executing query: = ) AND ( = ) ...
- Calendar 对象的使用实例
1.Calendar demo例子 JavaCalendar 类时间操作,示范代码. public class CalendarDemo { private static SimpleDateForm ...
- Action过滤器使用实例(一)
1.实例一 /// <summary> /// 需要用户登陆的 action,执行提前验证 /// </summary> public class LoginFilterAtt ...
- BFS(广搜)DFS(深搜)算法解析
图是一种灵活的数据结构,一般作为一种模型用来定义对象之间的关系或联系.对象由顶点(V)表示,而对象之间的关系或者关联则通过图的边(E)来表示. 图可以分为有向图和无向图,一般用G=(V,E)来表示图. ...
- otl翻译(11) -- OTL的迭代器
OTL stream read iterator 这个类是一个像传统的JDBC中的getter()操作一样扩展了OTL流的模板类.它现在还不支持UNICODE字符集.它对otl_refcur_stre ...
- go语言之进阶篇非结构体匿名字段
1.非结构体匿名字段 示例 : package main import "fmt" type mystr string //自定义类型,给一个类型改名 type Person st ...
- Android之TelephonyManager
在Android平台中,通过TelephonyManager可以访问与手机通讯相关的信息,比如设备信息.网络信息及SIM卡信息,同时还可以监听电话的相关状态.下面我们通过几个方面来说明Android平 ...
- idea 创建 简单的scala maven项目
1.创建maven scala项目 2.maven配置 <properties> <scala.version>2.11.8</scala.version> < ...
- MySQL有关1042 Can’t get hostname for your address的问题分析解决过程
[Comment 1] 前同事企鹅上面说他安装的mysql 5.5,发现用mysql客户端远程连接的时候,报1042-Can’t get hostname for your address错误,但是 ...