1
0

boxed_scalars.php 686 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. *
  4. * Boxed scalar values, usable with classes implementing Comparable_Interface.
  5. *
  6. * @copyright (c) 2007 OSI
  7. * @license Licensed under the CeCILL 2.0
  8. */
  9. /**
  10. * This class enables use of scalar values with classes implementing Comparable_Interface
  11. * @package default
  12. */
  13. class boxed_int implements Comparable_Interface {
  14. protected $value;
  15. function __construct($n) {
  16. $this->value = $n;
  17. }
  18. function cmp(Comparable_Interface $other) {
  19. if ($this->value < $other->value) {
  20. return -1;
  21. }
  22. elseif ($this->value > $other->value) {
  23. return 1;
  24. }
  25. else {
  26. return 0;
  27. }
  28. }
  29. function as_int() {
  30. return $this->value;
  31. }
  32. }