Menu

#203 Always tell user where he expected non-existing element

open
nobody
None
2025-11-06
2022-12-07
No
diff --git a/HtmlNode.php b/HtmlNode.php
index 9649d37..785e3d5 100644
--- a/HtmlNode.php
+++ b/HtmlNode.php
@@ -549,3 +549,7 @@ class HtmlNode
        {

-               return $this->find($selector, $idx, $lowercase) ?: null;
+               if(!$element = $this->find($selector, $idx, $lowercase)) {
+                       $stack = debug_backtrace();
+                       error_log(sprintf("%s(%s):Element not found: %s", $stack[0]["file"], $stack[0]["line"], $stack[0]["args"][0]));
+               }
+               return $element;
        }

Discussion

  • Anonymous

    Anonymous - 2022-12-09

    Actually it has to be done something like this, because this function can be called from inside the library, and we want to get the first call that is outside the library.

    PS! Is the maintainer active these days? Has been quiet for a while.

    diff --git a/HtmlNode.php b/HtmlNode.php
    index 9649d37..99dbda4 100644
    --- a/HtmlNode.php
    +++ b/HtmlNode.php
    @@ -549,3 +554,12 @@ class HtmlNode
            {
    
    -               return $this->find($selector, $idx, $lowercase) ?: null;
    +               if(!$element = $this->find($selector, $idx, $lowercase)) {
    +                       $stack = debug_backtrace();
    +                       foreach($stack as $call) {
    +                               if(!preg_match("~/simple_html_dom/~", $call["file"])) {
    +                                       error_log(sprintf("%s(%s):Element not found: %s", $call["file"], $call["line"], $call["args"][0]));
    +                                       break;
    +                               }
    +                       }
    +               }
    +               return $element;
            }
    
     
  • Anonymous

    Anonymous - 2025-11-06

    DELETE THIS BUG REPORT

     

Log in to post a comment.

MongoDB Logo MongoDB