Read the source code of the Zend engine in the PHP kernel system (original)

Source: Internet
Author: User

Read the source code of the Zend engine in the PHP kernel system (original)
Author: Yu Chao Email:

It's okay at home on weekends. One person reads the kernel,
The following code is displayed in lines 94-100 of the file Zend/zend_object_handlers.h, which is not clear to many people,
At first, I was confused. Then I analyzed it carefully and wrote down my experiences.
/* Object maintenance/destruction */
Typedef void (* zend_object_add_ref_t) (zval * object tsrmls_dc );
Typedef void (* zend_object_del_ref_t) (zval * object tsrmls_dc );
Typedef void (* zend_object_delete_obj_t) (zval * object tsrmls_dc );
Typedef zend_object_value (* zend_object_clone_obj_t) (zval * object tsrmls_dc );

First, in simple terms, typedef defines an alias, typedef int intger; then intger can define an integer variable.
Similarly, void (* terminate_handler) (); is a function pointer declaration. it is to declare a pointer to a function, pointing to a function without parameters and returning a value of void. for example, void fun (), you can use this pointer to point to the fun function. that is, terminate_handler = fun; // This indicates that the pointer terminate_handler points to the fun () function. however, if the void fun1 (int A) or Int fun2 () function tries to use the terminate_handler pointer to point to the two functions, that is, terminate_handler = fun1 or terminate_handler = fun2, an error occurs.
In this way:
Typedef void (* terminate_handler )();
Typedef is to name this type of pointer type as terminate_handler
You can use terminate_handler to generate a function pointer. For example, terminate_handler p; p = fun;
Terminate_handler is a type.

The English version is described as follows:
Typedef type-declaration synonym;

The typedef keyword defines a synonym for the specified type-declaration. The identifier in the type-declaration becomes another name for the type, instead of naming an instance of the type. You cannot
Use the typedef specifier inside a function definition.

A typedef declaration introduces a name that, within its scope, becomes a synonym for the type given by the decl-specifiers portion of the declaration. In contrast to the class, struct, union, and
Enum declarations, typedef declarations do not introduce new types-they introduce new names for existing types.


// Example of the typedef keyword
Typedef unsigned long ulong;

Ulong ul; // equivalent to "unsigned long ul ;"

Typedef struct mystructtag
Int I;
Float F;
Char C;
} Mystruct;

Mystruct MS; // equivalent to "struct mystructtag MS ;"

Typedef int (* funcptr) (); // funcptr is synonym for "pointer
// To function returning int"

Funcptr table [10]; // Equivalent to "int (* table [10]) ();"

Therefore, you can see many similar definitions in the zend/zend_API.h file of the zend engine.
Struct _ zend_object_handlers {
/* General object functions */
/* Individual object functions */
Defines the object structure in PHP.
Haha, is there a lot of gains? Please give your comments ..

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.