问题描述
我有一个非常尴尬的特定问题与simplexml评估。
I got a very awkward and specific issue with a simplexml evaluation.
代码:
$simplexml = simplexml_load_string($xmlstring);
var_dump($simplexml);
var_dump($simplexml == false); //this comparison
var_dump($ simplexml)返回我的simplexml的实际结构, true'对于这个特定的simplexml,我不能显示结构,因为我的合同。
我相信这是非常具体的问题,因为我尝试其他XML字符串,比较返回'false' 。
var_dump($simplexml) returns the actual structure of my simplexml but the comparison returns 'true' for this specific simplexml, which I can't show the structure because of my contract.
I'm sure that's very specifc issue 'cause I tried other XML strings and the comparison returns 'false'.
$simplexml = simplexml_load_string('<a><b>test</b></a>');
var_dump($simplexml); //returns the actual structure
var_dump($simplexml == false); //returns false
我使用'==='运算符解决了问题,不满意只是让它工作。我想知道为什么'=='运算符返回true。
我读了两个运算符和SimpleXMLElement,在我看来,它应该为这两个运算符返回'false'。
成功解析SimpleXMLElement和布尔值false之间进行比较以返回true的可能原因是什么?
I solved the problem using the '===' operator, but I'm not satisfied with just making it work. I want to understand why the '==' operator returns true.
I read about the two operators and the SimpleXMLElement and on my sight it should return 'false' for both operators.What are the possible reasons for a comparison between a succesfully parsed SimpleXMLElement and the boolean 'false' to return 'true'?
推荐答案
看看这里:
它表示从空标签创建的SimpleXML对象的值为false。也许这是怎么回事?
It says that SimpleXML objects created from empty tags evaluate to false. Maybe that's what's going on?
这篇关于成功解析SimpleXMLElement比较'false'返回'true'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!