Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. <?php
  2. function bool2str($bool)
  3. {
  4. if ($bool === false) {
  5. return 'FALSE';
  6. } else {
  7. return 'TRUE';
  8. }
  9. }
  10.  
  11. function compareObjects(&$o1, &$o2)
  12. {
  13. echo 'o1 == o2 : ' . bool2str($o1 == $o2) . "\n";
  14. echo 'o1 != o2 : ' . bool2str($o1 != $o2) . "\n";
  15. echo 'o1 === o2 : ' . bool2str($o1 === $o2) . "\n";
  16. echo 'o1 !== o2 : ' . bool2str($o1 !== $o2) . "\n";
  17. }
  18.  
  19. class Flag
  20. {
  21. public $flag;
  22.  
  23. function Flag($flag = true) {
  24. $this->flag = $flag;
  25. }
  26. }
  27.  
  28. class OtherFlag
  29. {
  30. public $flag;
  31.  
  32. function OtherFlag($flag = true) {
  33. $this->flag = $flag;
  34. }
  35. }
  36.  
  37. $o = new Flag();
  38. $p = new Flag();
  39. $q = $o;
  40. $r = new OtherFlag();
  41.  
  42. echo "Two instances of the same class\n";
  43. compareObjects($o, $p);
  44.  
  45. echo "\nTwo references to the same instance\n";
  46. compareObjects($o, $q);
  47.  
  48. echo "\nInstances of two different classes\n";
  49. compareObjects($o, $r);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement