Why this two objects are equal (==)?

In PHP I have two objects, they are different because of the $_frets variable (x is a string "x"), but PHP says

($o1 == $o2) == TRUE.

Why?

Dump of $o1 :

guitarChord Object
(
    [_guitarChord:guitarChord:private] => 
    [_chord:guitarChord:private] => chord Object()
    [_baseFret:guitarChord:private] => 0
    [_frets:guitarChord:private] => Array
        (
            [0] => x
            [1] => 0
            [2] => 2
            [3] => 2
            [4] => 2
            [5] => x
        )

    [_tuning:guitarChord:private] => tuning Object()
    [currVariation] => 0
    [nextVariation] => 
    [prevVariation] => 
)

Dump of $o2 :

guitarChord Object
(
    [_guitarChord:guitarChord:private] => 
    [_chord:guitarChord:private] => chord Object()
    [_baseFret:guitarChord:private] => 0
    [_frets:guitarChord:private] => Array
        (
            [0] => x
            [1] => 0
            [2] => 2
            [3] => 2
            [4] => 2
            [5] => 0
        )

    [_tuning:guitarChord:private] => tuning Object()
    [currVariation] => 0
    [nextVariation] => 
    [prevVariation] => 
)

EDIT:

So the reason why is because ("x" == 0) = TRUE . Can anyone tell me why?


Does x represent a string or does x represent null? If it represents null, then this is my theory: the Comparison Operators page has a transcription of the array comparison algorithm in Example #1. Based on this, I would imagine that in your case, what would end up happening is a comparison between 0 and null. According to the table above that, when null is compared to anything, it is converted to a bool. So you end up comparing 0 (false) to null (false), resulting in the two arrays being considered equal.

链接地址: http://www.djcxy.com/p/52862.html

上一篇: 存储大型前缀树的最佳方法

下一篇: 为什么这两个对象是相等的(==)?