1
0

boxed_scalars.php 580 B

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