Understanding PHP NULL from storage structure, null,0 ' 0 ' false____ storage

Source: Internet
Author: User
I believe that many developers are familiar with the 0 "0" null false ' explanation on the network, but I believe there is always the details you ignore, or from the variable structure point of view, how to explain. Then look at the verification below.
Echo ' PHP version: '. Php_version; 
5.6.28 $a = 0; 
$b = "0"; 
$c = '; 
$d = null;

$e = false;
	echo "5 variables-original test Type"; Var_dump ($a);//int 0 var_dump ($b);//string ' 0 ' var_dump ($c);//string ' Var_dump ($d);//null var_dump ($e);//boolean FAL
	Se echo " 


Summary: for "0;" 0 ";"; null, false "five types of empty operation above five variables, all return false strong equal to (= = =) comparison all false, same strong language result but for (= =) comparison, you need to pay attention to the string type, involves the underlying structure and type conversions
Conclusion One: The understanding of the variable type 1.null does not exist: PHP's Zval space (below the structure below) does not hold its value value, stores only one type flag its is_null (so explains empty (null) =true,isset (null ) =false, Isset (') =true) 2. "0; "0"; "" ; False ": These four for existence, PHP bottom is to open zval space storage, have value, have type
Conclusion Two: From the understanding of the underlying structure of the above conclusion, then the conclusion is easy to understand, it is not clear enough to see the "storage mechanism of the PHP kernel (separation/change)" where the "1.zval structure", "2.zend_uchar Type" section
String ' 0 ' is not equal to string ', (think about it, the same type of comparison of "1 length" string how can be equal to "0 length" string, Zal in the value structure, the string value has len original) int 0 is equal to string ' null , (non-homogeneous comparison, PHP will do type conversion)
String ' 0 ' is not equal to null int 0 is equal to NULL
plainly, for PHP, you encounter string "0" when the equation is judged, pause and notice the line. Other equations are normal and are in line with popular PHP development thinking.

PHP variable Zval structure://Storing basic information of variables
struct _zval_struct {  
   /* Variable information * *  
   zvalue_value value;  /* Variable values are saved here 12 bytes  
   /zend_uint REFCOUNT;//4 Byte, variable reference counter  
   Zend_uchar type;   /* Active type Variable type 1 bytes  
   /zend_uchar is_ref;//whether the variable is & referenced, 0 is not a reference, 1 is a reference, 1 bytes  
};  

Holds the value of a variable
typedef Union _ZVALUE_VALUE {  
   long lval;      /* Long value *  
   /double dval;    /* Double value */  
   struct {  
   	char *val;//4 byte  
   	int len;   4 bytes  
   } str;  
   HashTable *ht;    /* Hash Table value */  
   zend_object_value obj;  
} zvalue_value;


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.