<?php class A { public $a; } class B extends A { public $b; } $a = new B(); $a->a = 0; $a->b = 1; $b = new B(); $b->a = 1; $b->b = 0; // This compare walks the properties_table in both objects directly, resulting in ->a being compared first. // Call this: Direct Compare // Ref: https://github.com/php/php-src/blob/b151e17bdfca573e0205cc90dc710f89d77f03cf/Zend/zend_object_handlers.c#L1517 var_dump($a < $b); // print_r() (or several other potential actions) forces the properties HashTable to be materialized, // It's not the output of this that matters, so ignore it. print_r($a, true); // Now that one of the objects has a HashTable version, we materialize the other and walk that instead. // Ordering of properties in properties_info is not (necessarily) the same as in the property slots. // Call this: HashTable Compare // Ref: https://github.com/php/php-src/blob/b151e17bdfca573e0205cc90dc710f89d77f03cf/Zend/zend_object_handlers.c#L1569 // Ref: https://github.com/php/php-src/blob/b151e17bdfca573e0205cc90dc710f89d77f03cf/Zend/zend_object_handlers.c#L70 var_dump($a < $b); // But all of the above about ordering is basically irrelevant since the Direct Compare algorith only returns 0 or 1 for equal/in-equal. The HashTable comparison returns a -1/0/1 tripple for actual relops comparisons. // Start over: unset($a, $b); $a = new B(); $a->a = 0; $a->b = 1; $b = new B(); $b->a = 1; $b->b = 0; var_dump($a < $b); var_dump($b < $a);
You have javascript disabled. You will not be able to edit any code.