bug67949.phpt 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. --TEST--
  2. Bug #67949: DOMNodeList elements should be accessible through array notation
  3. --FILE--
  4. <?php
  5. $html = <<<HTML
  6. <div>data</div>
  7. <a href="test">hello world</a>
  8. HTML;
  9. $doc = new DOMDocument;
  10. $doc->loadHTML($html);
  11. $nodes = $doc->getElementsByTagName('div');
  12. echo "testing has_dimension\n";
  13. var_dump(isset($nodes[0]));
  14. var_dump(isset($nodes[1]));
  15. var_dump(isset($nodes[-1]));
  16. echo "testing property access\n";
  17. var_dump($nodes[0]->textContent);
  18. var_dump($nodes[1]->textContent);
  19. echo "testing offset not a long\n";
  20. $offset = ['test'];
  21. var_dump($offset);
  22. var_dump(isset($nodes[$offset]), $nodes[$offset]->textContent);
  23. var_dump($offset);
  24. $something = 'test';
  25. $offset = &$something;
  26. var_dump($offset);
  27. var_dump(isset($nodes[$offset]), $nodes[$offset]->textContent);
  28. var_dump($offset);
  29. $offset = 'test';
  30. var_dump($offset);
  31. var_dump(isset($nodes[$offset]), $nodes[$offset]->textContent);
  32. var_dump($offset);
  33. echo "testing read_dimension with null offset\n";
  34. var_dump($nodes[][] = 1);
  35. echo "testing attribute access\n";
  36. $anchor = $doc->getElementsByTagName('a')[0];
  37. var_dump($anchor->attributes[0]->name);
  38. echo "==DONE==\n";
  39. --EXPECTF--
  40. testing has_dimension
  41. bool(true)
  42. bool(false)
  43. bool(false)
  44. testing property access
  45. string(4) "data"
  46. Notice: Trying to get property of non-object in %s on line %d
  47. NULL
  48. testing offset not a long
  49. array(1) {
  50. [0]=>
  51. string(4) "test"
  52. }
  53. Notice: Trying to get property of non-object in %s on line %d
  54. bool(false)
  55. NULL
  56. array(1) {
  57. [0]=>
  58. string(4) "test"
  59. }
  60. string(4) "test"
  61. bool(true)
  62. string(4) "data"
  63. string(4) "test"
  64. string(4) "test"
  65. bool(true)
  66. string(4) "data"
  67. string(4) "test"
  68. testing read_dimension with null offset
  69. NULL
  70. testing attribute access
  71. string(4) "href"
  72. ==DONE==