1
0

boxed_scalars.php 561 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /**
  3. * This class enables use of scalar values with classes implementing Comparable_Interface
  4. * $Id: boxed_scalars.php,v 1.2 2007-06-03 21:23:38 marand Exp $
  5. */
  6. class boxed_int implements Comparable_Interface
  7. {
  8. protected $value;
  9. function __construct($n)
  10. {
  11. $this->value = $n;
  12. }
  13. function cmp(Comparable_Interface $other)
  14. {
  15. if ($this->value < $other->value)
  16. return -1;
  17. elseif ($this->value > $other->value)
  18. return 1;
  19. else
  20. return 0;
  21. }
  22. function as_int()
  23. {
  24. return $this->value;
  25. }
  26. }