arrayObject_count_basic1.phpt 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. --TEST--
  2. SPL: ArrayObject::count() and ArrayIterator::count() basic functionality.
  3. --FILE--
  4. ==ArrayObject==
  5. <?php
  6. class C extends ArrayObject {
  7. function count() {
  8. return 99;
  9. }
  10. }
  11. $c = new C;
  12. $ao = new ArrayObject;
  13. var_dump(count($c), count($ao));
  14. $c[] = 'a';
  15. $ao[] = 'a';
  16. var_dump(count($c), count($ao));
  17. $c[] = 'b';
  18. $ao[] = 'b';
  19. var_dump(count($c), count($ao));
  20. unset($c[0]);
  21. unset($ao[0]);
  22. var_dump($c->count(), $ao->count());
  23. //Extra args are ignored.
  24. var_dump($ao->count('blah'));
  25. ?>
  26. ==ArrayIterator==
  27. <?php
  28. class D extends ArrayIterator {
  29. function count() {
  30. return 99;
  31. }
  32. }
  33. $c = new D;
  34. $ao = new ArrayIterator;
  35. var_dump(count($c), count($ao));
  36. $c[] = 'a';
  37. $ao[] = 'a';
  38. var_dump(count($c), count($ao));
  39. $c[] = 'b';
  40. $ao[] = 'b';
  41. var_dump(count($c), count($ao));
  42. unset($c[0]);
  43. unset($ao[0]);
  44. var_dump($c->count(), $ao->count());
  45. //Extra args are ignored.
  46. var_dump($ao->count('blah'));
  47. ?>
  48. --EXPECTF--
  49. ==ArrayObject==
  50. int(99)
  51. int(0)
  52. int(99)
  53. int(1)
  54. int(99)
  55. int(2)
  56. int(99)
  57. int(1)
  58. Warning: ArrayObject::count() expects exactly 0 parameters, 1 given in %s on line %d
  59. NULL
  60. ==ArrayIterator==
  61. int(99)
  62. int(0)
  63. int(99)
  64. int(1)
  65. int(99)
  66. int(2)
  67. int(99)
  68. int(1)
  69. Warning: ArrayIterator::count() expects exactly 0 parameters, 1 given in %s on line %d
  70. NULL