NotionCommotion Posted May 8, 2017 Share Posted May 8, 2017 <?php function bool2str($bool) { if ($bool === false) { return 'FALSE'; } else { return 'TRUE'; } } function compareObjects(&$o1, &$o2) { echo '$o1'."\n"; var_dump($o1); echo '$o2'."\n"; var_dump($o2); echo 'o1 == o2 : ' . bool2str($o1 == $o2) . "\n"; echo 'o1 != o2 : ' . bool2str($o1 != $o2) . "\n"; echo 'o1 === o2 : ' . bool2str($o1 === $o2) . "\n"; echo 'o1 !== o2 : ' . bool2str($o1 !== $o2) . "\n\n\n"; } $o1 = new \stdClass; $o1->a=123; $o1->b=222; $o1->c=321; $o2 = new \stdClass; $o2->c=321; $o2->b=222; $o2->a=123; $o3 = new \stdClass; $o3->a=123; $o3->b=222; $o3->c=321; compareObjects($o1, $o1); compareObjects($o1, $o2); compareObjects($o1, $o3); $o1 object(stdClass)#1 (3) { ["a"]=> int(123) ["b"]=> int(222) ["c"]=> int(321) } $o2 object(stdClass)#1 (3) { ["a"]=> int(123) ["b"]=> int(222) ["c"]=> int(321) } o1 == o2 : TRUE o1 != o2 : FALSE o1 === o2 : TRUE o1 !== o2 : FALSE $o1 object(stdClass)#1 (3) { ["a"]=> int(123) ["b"]=> int(222) ["c"]=> int(321) } $o2 object(stdClass)#2 (3) { ["c"]=> int(321) ["b"]=> int(222) ["a"]=> int(123) } o1 == o2 : TRUE o1 != o2 : FALSE o1 === o2 : FALSE o1 !== o2 : TRUE $o1 object(stdClass)#1 (3) { ["a"]=> int(123) ["b"]=> int(222) ["c"]=> int(321) } $o2 object(stdClass)#3 (3) { ["a"]=> int(123) ["b"]=> int(222) ["c"]=> int(321) } o1 == o2 : TRUE o1 != o2 : FALSE o1 === o2 : FALSE o1 !== o2 : TRUE Quote Link to comment https://forums.phpfreaks.com/topic/303899-does-the-order-of-an-objects-properties-mean-anything/ Share on other sites More sharing options...
Solution requinix Posted May 8, 2017 Solution Share Posted May 8, 2017 Order does not matter. Loose object comparison works like an array comparison. Quote Link to comment https://forums.phpfreaks.com/topic/303899-does-the-order-of-an-objects-properties-mean-anything/#findComment-1546337 Share on other sites More sharing options...
NotionCommotion Posted May 8, 2017 Author Share Posted May 8, 2017 Order does not matter. Loose object comparison works like an array comparison. Guess I kind of knew that as my little script proved it. Still thought "maybe" there was some scenario where it might. Thanks for the confirmation. Quote Link to comment https://forums.phpfreaks.com/topic/303899-does-the-order-of-an-objects-properties-mean-anything/#findComment-1546340 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.