Albo ja jestem przemęczony, albo PHP świruje i to kolejne z jego "FUCK LOGIC"
Może ktoś wie co jest grane i o co może chodzić ?
Mianowicie chodzi o porównywanie obiektów, w dokumentacji możemy przeczytać:
Cytat
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).
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.
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).
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.
Na prostym przykładzie możemy zobaczyć zachowanie tej zależności
class A { protected $property; public function __construct($value) { $this->property = $value; } } $object1 = new A('ABC'); $object2 = new A('XYZ'); // Instances are not equal because of different value of property
Ok, PHP stwierdził, że obiekty nie są sobie równe - zgadza się.
Więc teraz użyłem obiektów mojej klasy, przekazałem różne wartości parametrów do konstruktora
Wartości parametrów są umieszczane we właściwościach klasy.
// Creating an instance of class with some parameters // Each of parameter will be stored as class property $object1 = new ComparsionRule('ABadasdC', ComparsionRule::LESS_THAN_OR_EQUAL); // Creating an instance of class with some different parameters // Each of parameter will be stored as class property $object2 = new ComparsionRule('XYZ', ComparsionRule::NOT_EQUAL_TO); // Two instances should not be equal (false expected) // Printing content of first object // Printing content of second object // Checking the expression again // Two instances should not be equal (false expected) die;
Wynik jest zaskakujący, najpierw PHP stwierdza, że obiekty są sobie równe
Następnie wyświetla te obiekty i ponownie sprawdza czy są sobie równe, ale tym razem stwierdza, że jednak nie są równe
Załączam screenshot, na którym widać zawartość obu obiektów oraz te dziwne chwiejne wyniki porównania
