在两个不同的服务器上获取空对象的数量是不同的..!
Getting count of empty object on two different servers are different..!
I am getting count of empty object as a '0' on local server and count of same empty obejct as a '1' on different server using PHP.
Can anybody give me some information whether we can set count start value in PHP or what is the reason behind this.
BElow is the sample xml :
<customer>
<name></name>
<address></address>
<Contact>
<!--<Mobile></Mobile>-->
<!--<Mobile></Mobile>-->
<Work></Work>
<Home></Home>
</Contact>
</customer>
我正在根据上述 xml 构建对象,然后从该对象中获取值。
例如:喜欢:$object->customer->contact->Mobile
如果我在 xml 中没有 Mobile 标签,则会引发此问题:
var_dump($object->customer->contact->Mobile);
阅读 count()
文档中的这些摘录:
For objects, if you have SPL installed, you can hook into count() by
implementing interface Countable. The interface has exactly one
method, Countable::count(), which returns the return value for the
count() function.
还有...
Returns the number of elements in array_or_countable. If the parameter
is not an array or not an object with implemented Countable interface,
1 will be returned. There is one exception, if array_or_countable is
NULL, 0 will be returned.
如果您没有在一个地方安装 SPL and/or 没有实现 Countable
接口的 class,您可能会得到意想不到的结果。
编辑:我看到您在这里使用 SimpleXMLElement。它没有实现 Countable
,所以你不应该尝试 count()
它。
I am getting count of empty object as a '0' on local server and count of same empty obejct as a '1' on different server using PHP.
Can anybody give me some information whether we can set count start value in PHP or what is the reason behind this.
BElow is the sample xml :
<customer>
<name></name>
<address></address>
<Contact>
<!--<Mobile></Mobile>-->
<!--<Mobile></Mobile>-->
<Work></Work>
<Home></Home>
</Contact>
</customer>
我正在根据上述 xml 构建对象,然后从该对象中获取值。
例如:喜欢:$object->customer->contact->Mobile
如果我在 xml 中没有 Mobile 标签,则会引发此问题:
var_dump($object->customer->contact->Mobile);
阅读 count()
文档中的这些摘录:
For objects, if you have SPL installed, you can hook into count() by implementing interface Countable. The interface has exactly one method, Countable::count(), which returns the return value for the count() function.
还有...
Returns the number of elements in array_or_countable. If the parameter is not an array or not an object with implemented Countable interface, 1 will be returned. There is one exception, if array_or_countable is NULL, 0 will be returned.
如果您没有在一个地方安装 SPL and/or 没有实现 Countable
接口的 class,您可能会得到意想不到的结果。
编辑:我看到您在这里使用 SimpleXMLElement。它没有实现 Countable
,所以你不应该尝试 count()
它。