Statement: This article is an original article by the author, all of which have been analyzed by the author one by one. I hope you can give me some advice if there is something wrong with it.
You are welcome to reprint it. Please indicate the source for reprinting.
Address: http://imsiren.com/archives/516
The previous article described the source code analysis of the PHP kernel: isset and
Empty
But it seems that I have forgotten a series of is functions.
For example
Is_null, is_object, is_array, is_string, is_resource, is_bool, is_long, is_float
Today I will try again... their judgment methods are the same. Only one is_null and others will be able to understand.
Is_null is a function. It is defined in the EXT/standard/type. c file.
All types of operations are in this file. settype, GetType, intval, and other functions are also here.
PHP_FUNCTION(is_null){ php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_NULL);}
It calls the php_is_type function, which is followed by the type to be checked.
staticvoid php_is_type(INTERNAL_FUNCTION_PARAMETERS, inttype){ zval **arg; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &arg) == FAILURE) { RETURN_FALSE; } if(Z_TYPE_PP(arg) == type) { if(type == IS_OBJECT) { zend_class_entry *ce; if(Z_OBJ_HT_PP(arg)->get_class_entry == NULL) { /* if there's no get_class_entry it's not a PHP object, so it can't be INCOMPLETE_CLASS */ RETURN_TRUE; } ce = Z_OBJCE_PP(arg); if(!strcmp(ce->name, INCOMPLETE_CLASS)) { RETURN_FALSE; } } if(type == IS_RESOURCE) { char*type_name; type_name = zend_rsrc_list_get_rsrc_type(Z_LVAL_PP(arg) TSRMLS_CC); if(!type_name) { RETURN_FALSE; } } RETURN_TRUE; }else{ RETURN_FALSE; }}
The ninth line will call z_type_pp to obtain the type of the passed value.
If the value is not equal to the type of the second parameter of the function, false is directly returned;
If it is equal to the type we want to detect, but the object or resource needs to be determined accordingly.
If it is an object, the sixteen lines will get the name value of the _ zend_class_entry structure, which must be equal to incomplete_class
Incomplete_class is a macro,
# Define incomplete_class "_ php_incomplete_class"
That is to say, a class must be instantiated.
Source: http://imsiren.com/archives/516