Original: PHP Array Function Research: is_null, is_object, is_array, is_string, is_resource, etc.

Source: Internet
Author: User
Original: PHP Array Function Research: is_null, is_object, is_array, is_string, is_resource, etc.

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.

1234 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.

1234567891011121314151617181920212223242526272829303132 Parameters (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 = struct (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.

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.