Menu

#201 Never return false on documents

open
nobody
None
2025-11-06
2022-10-11
No

Isn't it a bad idea returning false for non-existing (or too large) documents? Because this triggers a fatal error and the entire script halts, even though the problem is just local to a single document. Returning null triggers a non-fatal error and the script continues, which seems better.

$html = file_get_html("404.html");
simple_html_dom/simple_html_dom.php(113):file_get_contents(404.html): Failed to open stream: No such file or directory
$items = $html->expect(".bar");
PHP Fatal error:  Uncaught Error: Call to a member function expect() on bool
diff --git a/simple_html_dom.php b/simple_html_dom.php
index bce4d9e..095245f 100644
--- a/simple_html_dom.php
+++ b/simple_html_dom.php
@@ -117,3 +117,3 @@ function file_get_html(
                $dom->clear();

-               return false;
+               //return false;
        }
@@ -144,3 +144,3 @@ function str_get_html(
                $dom->clear();
-               return false;
+               //return false;
        }

Discussion

  • Anonymous

    Anonymous - 2022-12-07
    diff --git a/simple_html_dom.php b/simple_html_dom.php
    index bce4d9e..97d6e1d 100644
    --- a/simple_html_dom.php
    +++ b/simple_html_dom.php
    @@ -117,3 +117,3 @@ function file_get_html(
                    $dom->clear();
    
    -               return false;
    +               $contents = "";
            }
    @@ -144,5 +144,4 @@ function str_get_html(
                    $dom->clear();
    -               return false;
    +               $contents = "";
            }
    -
            return $dom->load($str, $lowercase, $stripRN);
    

    Better version with tabs.

    PS! The inline editor and preview function on the site seems to hide the first line of content :|

     
  • Anonymous

    Anonymous - 2025-11-06

    DELETE THIS BUG REPORT

     

Log in to post a comment.

MongoDB Logo MongoDB