bug67949.phpt 1.8 KB

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