fixedarray_002.phpt 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. --TEST--
  2. SPL: FixedArray: overloading
  3. --FILE--
  4. <?php
  5. class A extends SplFixedArray {
  6. public $prop1 = NULL;
  7. public $prop2 = NULL;
  8. public function count() {
  9. return 2;
  10. }
  11. public function offsetGet($n) {
  12. echo "A::offsetGet\n";
  13. return parent::offsetGet($n);
  14. }
  15. public function offsetSet($n, $v) {
  16. echo "A::offsetSet\n";
  17. return parent::offsetSet($n, $v);
  18. }
  19. public function offsetUnset($n) {
  20. echo "A::offsetUnset\n";
  21. return parent::offsetUnset($n);
  22. }
  23. public function offsetExists($n) {
  24. echo "A::offsetExists\n";
  25. return parent::offsetExists($n);
  26. }
  27. }
  28. $a = new A;
  29. // errors
  30. try {
  31. $a[0] = "value1";
  32. } catch (RuntimeException $e) {
  33. echo "Exception: ".$e->getMessage()."\n";
  34. }
  35. try {
  36. var_dump($a["asdf"]);
  37. } catch (RuntimeException $e) {
  38. echo "Exception: ".$e->getMessage()."\n";
  39. }
  40. try {
  41. unset($a[-1]);
  42. } catch (RuntimeException $e) {
  43. echo "Exception: ".$e->getMessage()."\n";
  44. }
  45. $a->setSize(10);
  46. $a[0] = "value0";
  47. $a[1] = "value1";
  48. $a[2] = "value2";
  49. $a[3] = "value3";
  50. $ref = "value4";
  51. $ref2 =&$ref;
  52. $a[4] = $ref;
  53. $ref = "value5";
  54. unset($a[1]);
  55. var_dump(isset($a[1]), isset($a[2]), empty($a[1]), empty($a[2]));
  56. var_dump($a[0], $a[2], $a[3], $a[4]);
  57. // countable
  58. var_dump(count($a), $a->getSize(), count($a) == $a->getSize());
  59. ?>
  60. ===DONE===
  61. --EXPECT--
  62. A::offsetSet
  63. Exception: Index invalid or out of range
  64. A::offsetGet
  65. Exception: Index invalid or out of range
  66. A::offsetUnset
  67. Exception: Index invalid or out of range
  68. A::offsetSet
  69. A::offsetSet
  70. A::offsetSet
  71. A::offsetSet
  72. A::offsetSet
  73. A::offsetUnset
  74. A::offsetExists
  75. A::offsetExists
  76. A::offsetExists
  77. A::offsetExists
  78. bool(false)
  79. bool(true)
  80. bool(true)
  81. bool(false)
  82. A::offsetGet
  83. A::offsetGet
  84. A::offsetGet
  85. A::offsetGet
  86. string(6) "value0"
  87. string(6) "value2"
  88. string(6) "value3"
  89. string(6) "value4"
  90. int(2)
  91. int(10)
  92. bool(false)
  93. ===DONE===