Comparing objects 对象比较
In PHP 5, object comparison is more complicated than in PHP 4 and more in accordance to what one will expect from an Object Oriented Language (not that PHP 5 is such a language).
在php5中,对象比较会比在php4中更加复杂,更加像面向对象语言(这倒不是说php5不是面对对象语言)
When using the comparison operator (== ), object variables are compared in a simple manner, namely: Two object instances are equal if they have the same attributes and values, and are instances of the same class.
当用(==)比较两个对象的时候,比较的方法是非常简单的,也就是说:当两个对象实例具有相同的属性和值,并且是同一个类的实例,那么他们就相等。
On the other hand, when using the identity operator (=== ), object variables are identical if and only if they refer to the same instance of the same class.
在另一方面,当我们用恒等运算符(===),如果两个比较的对象是同一个类的的同一个实例那么这两个对象恒等。
An example will clarify these rules.
下面这个例子会说明这些规则。
上例将输出: