PHP7 Kernel Analysis 8 and the like
The content of this article is about PHP7 kernel analysis 8 and so on. Now I share it with you. Friends in need can refer to it
1. Class structure
Class is the product of the compilation phase. After compilation, each class we define will generate a zend_class_entry, which stores all the information of the class. During the execution phase, all class-related operations use this structure
struct _zend_class_entry { char type; //类的类型:内部类ZEND_INTERNAL_CLASS(1)、用户自定义类ZEND_USER_CLASS(2) zend_string *name; //类名,PHP类不区分大小写,统一为小写 struct _zend_class_entry *parent; //父类 int refcount; uint32_t ce_flags; //类掩码,如普通类、抽象类、接口, int default_properties_count; //普通属性数,包括public、private int default_static_members_count; //静态属性数,static zval *default_properties_table; //普通属性值数组 zval *default_static_members_table; //静态属性值数组 zval *static_members_table; HashTable function_table; //成员方法哈希表 HashTable properties_info; //成员属性基本信息哈希表,key为成员名,value为zend_property_info HashTable constants_table; //常量哈希表,通过constant定义的 //以下是构造函授、析构函数、魔术方法的指针 union _zend_function *constructor; union _zend_function *destructor; union _zend_function *clone; union _zend_function *__get; union _zend_function *__set; union _zend_function *__unset; union _zend_function *__isset; union _zend_function *__call; union _zend_function *__callstatic; union _zend_function *__tostring; union _zend_function *__debugInfo; union _zend_function *serialize_func; union _zend_function *unserialize_func; }
2. Class constants
In PHP, values that always remain unchanged in the class can be defined as constants. When defining and using There is no need to use the $ symbol when using constants. The value of a constant must be a fixed value. They are stored through zend_class_entry.constants_table, which is a hash structure
常量的读取: class my_class { const A1 = "hi"; } echo my_class::A1; 编译到echo my_class::A1这行时首先会尝试检索下是否已经编译了my_class,如果能在CG(class_table)中找到,则进一步从类的contants_table查找对应的常量,找到的话则会复制其value替换常量,简单的讲就是类似C语言中的宏,编译时替换为实际的值了,而不是在运行时再去检索。 echo my_class::A1; class my_class { const A1 = "hi"; } 在运行时再去检索。替换成为实际的值
3. Member attributes
The variables in the attributes can be initialized, but the initialized value must be a constant. The constant here means that the PHP script can get its value during the compilation phase, and does not depend on Only runtime information can be evaluated, such as public $time = time(); defining a property in this way will trigger a syntax error.Member attributes are divided into two categories: ordinary attributes and static attributes. Different from the storage method of constants, the initialization value of member attributes is not directly stored in the hash table with "attribute name" as the index, but through The
# saved in the array is actually just the VALUE of the member attribute stored in the array. When accessed, it is still based on the "attribute name" as the index. The hash table looks for a specific VALUE, and this hash table is zend_class_entry.properties_info
typedef struct _zend_property_info { uint32_t offset; //普通成员变量的内存偏移值,静态成员变量的数组索引 uint32_t flags; //属性掩码,如public、private、protected及是否为静态属性 zend_string *name; //属性名:并不是原始属性名,private会在原始属性名前加上类名,protected则会加上*作为前缀 zend_string *doc_comment; zend_class_entry *ce; //所属类 } zend_property_info;
##4. Member method
Each A class can define several functions (called member methods) that belong to this class. These functions are the same as ordinary functions, but are managed in the class dimension and are not global, so the member methods are stored in the class instead of EG ( function_table)5. Object data structure
typedef struct _zend_object zend_object; struct _zend_object { zend_refcounted_h gc; //引用计数 uint32_t handle; //对象编号 zend_class_entry *ce; //所属类 const zend_object_handlers *handlers; //对象操作处理函数 HashTable *properties; //普通成员属性哈希表 zval properties_table[1]; //普通属性值数组 };
PHP7 Kernel Analysis 7 Zend Engine Execution Process
PHP7 Kernel Analysis 6 Function
PHP7 Kernel Analysis 5 Compilation of PHP Code
The above is the detailed content of PHP7 Kernel Analysis 8 and the like. For more information, please follow other related articles on the PHP Chinese website!

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics











JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Causes and solutions for errors when using PECL to install extensions in Docker environment When using Docker environment, we often encounter some headaches...

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.
