Fixed [E_WARNING] Attempt to read property "result_count" on null

briansol

Well-known member
actually, it's not a php 8.1 issue.

i just got one on php 7.4.30


ErrorException: [E_NOTICE] Trying to get property 'result_count' of non-object src/XF/Pub/Controller/Search.php:153
Generated by: Unknown account Jul 13, 2022 at 3:08 PM
 

Brettflan

Active member
We're getting this error a bit more than once per minute on our large forum, even with it being a slow part of the day. So: we're also looking forward to a fix.
I'm tempted to just manually add a null check workaround fix to the file, but the resulting modified file contents warning would be annoying.
 
Yeah I rather have a daily file integrity warning until a fix is released than dozens of error log entries per minute..

So I applied the following diff as stop gap:

Diff:
--- src/XF/Pub/Controller/Search.orig.php    2022-07-14 09:15:02.888904630 +0200
+++ src/XF/Pub/Controller/Search.php    2022-07-14 09:14:47.017272442 +0200
@@ -143,12 +143,16 @@ class Search extends AbstractController
             }
             else if ($search && $search->search_query && $search->search_query !== $this->filter('q', 'str'))
             {
                 return $this->notFound();
             }
         }
+        # [ TL: workaround regression of 2.2.10 producing many errors with guests searching ]
+        if (!is_object($search)) {
+            return $this->message(\XF::phrase('no_results_found'));
+        }
 
         $page = $this->filterPage();
         $perPage = $this->options()->searchResultsPerPage;
 
         $this->assertValidPage($page, $perPage, $search->result_count, 'search', $search);

IOW, add the following hunk to the actionResults function before the $page = $this->filterPage(); line:

PHP:
if (!is_object($search)) {
    return $this->message(\XF::phrase('no_results_found'));
}

Stopped the error messages from piling up and didn't see any bad effect (albeit the actual fix is probably different)
 
Last edited:

djbaxter

Well-known member
I'm also getting this error after upgrading to 2.2.10 and I can confirm it appears to be just Guests using search (could well be bots).
 

mattrogowski

Well-known member
what's ironic is that i have search disabled for guests, and i'm still seeing it....
It's on the results page, the searches are stored and can be viewed back with a unique URL, and those don't seem to have a permissions check. The more intensive process of the search itself is already done at that point so I guess it doesn't need permission gating.
 

FTL

Well-known member
I see the same error on mine - two entries since upgrading to 2.2.10. Site seems to work ok otherwise though.
 

Ivo2

Member
I just downloaded and installed today and still get the error
Is it fixed or not? I'm a little bit confused
My errors:

Apache config:
#0 src/XF/Pub/Controller/Search.php(153): XF::handlePhpError(8, '[E_NOTICE] Tryi...', '/var/www/vhosts...', 153, Array)
#1 src/XF/Mvc/Dispatcher.php(352): XF\Pub\Controller\Search->actionResults(Object(XF\Mvc\ParameterBag))
#2 src/XF/Mvc/Dispatcher.php(259): XF\Mvc\Dispatcher->dispatchClass('XF\\Pub\\Controll...', 'Results', Object(XF\Mvc\RouteMatch), Object(XF\Pub\Controller\Search), Object(XF\Mvc\Reply\Reroute))
#3 src/XF/Mvc/Dispatcher.php(115): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(XF\Pub\Controller\Search), Object(XF\Mvc\Reply\Reroute))
#4 src/XF/Mvc/Dispatcher.php(57): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#5 src/XF/App.php(2353): XF\Mvc\Dispatcher->run()
#6 src/XF.php(524): XF\App->run()
#7 index.php(20): XF::runApp('XF\\Pub\\App')
#8 {main}

PHP:
array(4) {
  ["url"] => string(22) "/search/154476/?page=2"
  ["referrer"] => string(51) "https://balkanforum.info/search/member?user_id=6209"
  ["_GET"] => array(1) {
    ["page"] => string(1) "2"
  }
  ["_POST"] => array(0) {
  }
}

Or that

Apache config:
#0 src/XF/Pub/Controller/Search.php(153): XF::handlePhpError(8, '[E_NOTICE] Tryi...', '/var/www/vhosts...', 153, Array)
#1 src/XF/Mvc/Dispatcher.php(352): XF\Pub\Controller\Search->actionResults(Object(XF\Mvc\ParameterBag))
#2 src/XF/Mvc/Dispatcher.php(259): XF\Mvc\Dispatcher->dispatchClass('XF\\Pub\\Controll...', 'Results', Object(XF\Mvc\RouteMatch), Object(XF\Pub\Controller\Search), Object(XF\Mvc\Reply\Reroute))
#3 src/XF/Mvc/Dispatcher.php(115): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(XF\Pub\Controller\Search), Object(XF\Mvc\Reply\Reroute))
#4 src/XF/Mvc/Dispatcher.php(57): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#5 src/XF/App.php(2353): XF\Mvc\Dispatcher->run()
#6 src/XF.php(524): XF\App->run()
#7 index.php(20): XF::runApp('XF\\Pub\\App')
#8 {main}

PHP:
array(4) {
  ["url"] => string(15) "/search/167217/"
  ["referrer"] => bool(false)
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(0) {
  }
}
 
Last edited:
Is it fixed or not? I'm a little bit confused
Not yet, see:
We are aiming to include any changes that have been made in a future XF release (2.2.11).
and 2.2.11 is not yet available.

FWIW, the errors are harmless, but due to their amount (depending on your setup) they may drown out other, possibly relevant errors.
My stop gap workaround from this thread still works, albeit it will result in a There are 1 missing files or files with unexpected contents. You should review these. warning, so until an upgrade is release you may choose what's the lesser "evil" for you :)
 
Top