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: yuchao86@gmail.com

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

// 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 */
Zend_object_add_ref_tadd_ref;
Zend_object_del_ref_tdel_ref;
Zend_object_clone_obj_tclone_obj;
/* Individual object functions */
Zend_object_read_property_tread_property;
Zend_object_write_property_twrite_property;
Zend_object_read_dimension_tread_dimension;
Zend_object_write_dimension_twrite_dimension;
Zend_object_get_property_ptr_ptr_tget_property_ptr_ptr;
Zend_object_get_tget;
Zend_object_set_tset;
Zend_object_has_property_thas_property;
Zend_object_unset_property_tunset_property;
Zend_object_has_dimension_thas_dimension;
Zend_object_unset_dimension_tunset_dimension;
Zend_object_get_properties_tget_properties;
Zend_object_get_method_tget_method;
Zend_object_call_method_tcall_method;
Zend_object_get_constructor_tget_constructor;
Zend_object_get_class_entry_tget_class_entry;
Zend_object_get_class_name_tget_class_name;
Zend_object_compare_tcompare_objects;
Zend_object_cast_tcast_object;
Zend_object_count_elements_tcount_elements;
Zend_object_get_debug_info_tget_debug_info;
Zend_object_get_closure_tget_closure;
};
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: info-contact@alibabacloud.com 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.