Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

var_dump( (pack("C" , 1)<<1) ==pack("C" , 1) );
为什么是true呢


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
922 views
Welcome To Ask or Share your Answers For Others

1 Answer

牵涉到 php 比较的时候,类型转换
1、pack("C" , 1)<<1 , 结果是 int(0)
2、pack("C" , 1) , 结果是 string("")

其实就简化成了 0 == "" 的比较

PHP 在比较的时候,如果类型不相等,会进行类型转换
这里就会把 string("") 转换成 int 类型,也就是会变成 int(0),所以这里返回 true

你要严格判断,可以使用 ===

var_dump( (pack("C" , 1)<<1) ===pack("C" , 1) ); 结果是 false


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...