foreach() receiving null values in getOutput method of Output.php
-
# foreach() receiving null values in getOutput method of Output.php # Details I'm getting an exception error reported by sentry saying that a foreach statement in getOutput method of popular posts is receiving null values. The stack trace is: **"ErrorException: Warning: foreach() argument must be of type array|object, null given"** The line it is referring to is
foreach( $body->childNodes as $node ) {
which is line 181 of web/app/plugins/wordpress-popular-posts/src/Output.php, in the getOutput method. Here is the full code in context for the public function getOutput that this line is inside of:
So far there appear to be no problems on the site itself, even on the page sentry is reporting that it is finding the error on. However, I wanted to investigate this issue before it became a larger problem. Wordpress version 6.4.3 PHP version 8.0.22 Plugin version 6.4.2 # Solution I was considering a defensive programming solution where I might check if the array?foreach( $body->childNodes as $node ) { $clean_html .= $dom->saveHTML($node); }
is_empy
??prior to the foreach, but since this is inside of a plugin, the only way can think to do that on my end is to create a patch. However, if a solution is already known for this issue or if patching would be overkill when there is a simpler solution, I would appreciate any assistance.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘foreach() receiving null values in getOutput method of Output.php’ is closed to new replies.