Doc #78252 [NEW]: Report a miss information in `Return Values` section of getElementsByTagName

From: Date: Fri, 05 Jul 2019 08:45:44 +0000
Subject: Doc #78252 [NEW]: Report a miss information in `Return Values` section of getElementsByTagName
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-16797@lists.php.net to get a copy of this message
From: dangtu dot work at gmail dot com Operating system: Windows 10 PHP version: 7.3.7 Package: DOM XML related Bug Type: Documentation Problem Bug description:Report a miss information in Return Values section of getElementsByTagName Description: ------------ --- From manual page: https://php.net/domdocument.getelementsbytagname --- There is a miss information in Return Values section of DOMDocument::getElementsByTagName. In the section, it only said: > A new DOMNodeList object containing all the matched elements But no info about what will return if no matched elements found! A sandbox come with result: http://sandbox.onlinephpfunctions.com/code/3b0f001e462a223188defd42554c8401b3626f8b Test script: --------------- <?php $html = <<< HTML <article id="p73" class="p-quote"> Albert Einstein’s Quotes Collection <blockquote><p>Life is like riding a bicycle. To keep your balance, you must keep moving.</p></blockquote> <blockquote><p>Pure mathematics is, in its way, the poetry of logical ideas.</p></blockquote> <blockquote><p>Education is what remains after one has forgotten what one has learned in school.</p></blockquote> <blockquote><p>Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning.</p></blockquote> <blockquote><p>Logic will get you from A to B. Imagination will take you everywhere.</p></blockquote> <blockquote><p>If you can’t explain it simply, you don’t understand it well enough.</p></blockquote> <blockquote><p>The difference between stupidity and genius is that genius has its limits.</p></blockquote> </article> HTML; class ExtractTag { private $doc = null; public function __construct($html) { $this->doc = new DomDocument(); $content = mb_convert_encoding( $html, 'HTML-ENTITIES', 'UTF-8' ); @$this->doc->loadHTML($content); } private function getFirstTag($tag) { return $this->doc->getElementsByTagName($tag)->item(0); } private function printFirstTag($tag) { $firstTag = $this->getFirstTag($tag); echo $this->doc->saveHTML($firstTag); } public function print_image() { $this->printFirstTag('img'); } public function print_quote() { $this->printFirstTag('blockquote'); } } $dom = new ExtractTag($html); echo $dom->print_quote(); #Expect to see a <blockquote> echo $dom->print_image(); #Expect to see nothing since there is no <img> tag in the html! Expected result: ---------------- The Return Values should be wrote like this: If matched elements found, the method will return a new DOMNodeList object containing all the matched elements. If nothing found, a DOMDocument itself will be returned. -- Edit bug report at https://bugs.php.net/bug.php?id=78252&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=78252&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=78252&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=78252&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=78252&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=78252&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=78252&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=78252&r=needscript Try newer version: https://bugs.php.net/fix.php?id=78252&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=78252&r=support Expected behavior: https://bugs.php.net/fix.php?id=78252&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=78252&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=78252&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=78252&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=78252&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=78252&r=dst IIS Stability: https://bugs.php.net/fix.php?id=78252&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=78252&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=78252&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=78252&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=78252&r=mysqlcfg

« previous php.doc.bugs (#16797) next »