PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/good/ext/spl/tests/bug66834.php

http://github.com/facebook/hiphop-php
PHP | 77 lines | 61 code | 12 blank | 4 comment | 0 complexity | 239d6e0301cbb4b633040f0fd5518b7b MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. // overrides both offsetExists and offsetGet
  3. class ArrayObjectBoth extends ArrayObject
  4. {
  5. public function offsetExists($offset) {
  6. var_dump('Called: '.__METHOD__);
  7. return parent::offsetExists($offset);
  8. }
  9. public function offsetGet($offset) {
  10. var_dump('Called: '.__METHOD__);
  11. return parent::offsetGet($offset);
  12. }
  13. }
  14. // overrides only offsetExists
  15. class ArrayObjectExists extends ArrayObject
  16. {
  17. public function offsetExists($offset) {
  18. var_dump('Called: '.__METHOD__);
  19. return parent::offsetExists($offset);
  20. }
  21. }
  22. // overrides only offsetGet
  23. class ArrayObjectGet extends ArrayObject
  24. {
  25. public function offsetGet($offset) {
  26. var_dump('Called: '.__METHOD__);
  27. return parent::offsetGet($offset);
  28. }
  29. }
  30. // overrides only offsetGet and offsetSet
  31. class ArrayObjectGetSet extends ArrayObject
  32. {
  33. public function offsetGet($offset)
  34. {
  35. return parent::offsetGet(str_rot13($offset));
  36. }
  37. public function offsetSet($offset, $value)
  38. {
  39. return parent::offsetSet(str_rot13($offset), $value);
  40. }
  41. }
  42. $values = ['foo' => '', 'bar' => null, 'baz' => 42];
  43. echo "==== class with offsetExists() and offsetGet() ====\n";
  44. $object = new ArrayObjectBoth($values);
  45. var_dump($object->offsetExists('foo'), isset($object['foo']), empty($object['foo']));
  46. var_dump($object->offsetExists('bar'), isset($object['bar']), empty($object['bar']));
  47. var_dump($object->offsetexists('baz'), isset($object['baz']), empty($object['baz']));
  48. var_dump($object->offsetexists('qux'), isset($object['qux']), empty($object['qux']));
  49. echo "==== class with offsetExists() ====\n";
  50. $object = new ArrayObjectExists($values);
  51. var_dump($object->offsetExists('foo'), isset($object['foo']), empty($object['foo']));
  52. var_dump($object->offsetExists('bar'), isset($object['bar']), empty($object['bar']));
  53. var_dump($object->offsetexists('baz'), isset($object['baz']), empty($object['baz']));
  54. var_dump($object->offsetexists('qux'), isset($object['qux']), empty($object['qux']));
  55. echo "==== class with offsetGet() ====\n";
  56. $object = new ArrayObjectGet($values);
  57. var_dump($object->offsetExists('foo'), isset($object['foo']), empty($object['foo']));
  58. var_dump($object->offsetExists('bar'), isset($object['bar']), empty($object['bar']));
  59. var_dump($object->offsetexists('baz'), isset($object['baz']), empty($object['baz']));
  60. var_dump($object->offsetexists('qux'), isset($object['qux']), empty($object['qux']));
  61. echo "==== class with offsetGet() and offsetSet() ====\n";
  62. $object = new ArrayObjectGetSet;
  63. $object['foo'] = 42;
  64. var_dump($object->offsetExists('foo'), $object->offsetExists('sbb'), isset($object['foo']), isset($object['sbb']), empty($object['sbb']));
  65. ?>