# Search result with matching landing page name generating fatal error

**URL:** <https://forum.mautic.org/t/search-result-with-matching-landing-page-name-generating-fatal-error/29317>\
**Category:** Product Support\
**Created:** [September 17, 2023, 4:27am UTC](https://forum.mautic.org/t/search-result-with-matching-landing-page-name-generating-fatal-error/29317 "2023-09-17T04:27:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mauticdeveloper](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mauticdeveloper/32/627_2.png) [@mauticdeveloper](https://forum.mautic.org/u/mauticdeveloper)\
**Post date:** [September 17, 2023, 4:27am UTC](https://forum.mautic.org/t/search-result-with-matching-landing-page-name-generating-fatal-error/29317/1 "2023-09-17T04:27:47Z")

</div>

**Your software**  
My Mautic version is: 4.4.7  
My PHP version is: 7.4  
My Database type and version is: MariaDb

**Your problem**  
My problem is:  
Global search generating error when search query matches landing pages name.  
These errors are showing in the log:

```auto
mautic.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalThrowableError: "Call to a member function getId() on array" at C:\xampp\htdocs\mautic\app\bundles\PageBundle\Views\SubscribedEvents\Search\global.html.php line 17 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Call to a member function getId() on array at C:\\xampp\\htdocs\\mautic\\app\\bundles\\PageBundle\\Views\\SubscribedEvents\\Search\\global.html.php:17)"} 

```

Steps I have tried to fix the problem:  
I have found the `app\bundles\PageBundle\Views\SubscribedEvents\Search\global.html.php` is receiving the array instead of object and when I change code in `app\bundles\PageBundle\EventListener\SearchSubscriber.php` file it fixes the issue but my concern is why it creating array instead of object.

Below is the original mautic code

```auto
public function onGlobalSearch(MauticEvents\GlobalSearchEvent $event)
    {
        $str = $event->getSearchString();
        if (empty($str)) {
            return;
        }

        $filter = ['string' => $str, 'force' => []];

        $permissions = $this->security->isGranted(
            ['page:pages:viewown', 'page:pages:viewother'],
            'RETURN_ARRAY'
        );
        if ($permissions['page:pages:viewown'] || $permissions['page:pages:viewother']) {
            if (!$permissions['page:pages:viewother']) {
                $filter['force'][] = [
                    'column' => 'IDENTITY(p.createdBy)',
                    'expr' => 'eq',
                    'value' => $this->userHelper->getUser()->getId(),
                ];
            }

            $pages = $this->pageModel->getEntities(
                [
                    'limit' => 5,
                    'filter' => $filter,
                ]);

            if (count($pages) > 0) {
                $pageResults = [];

                foreach ($pages as $page) {
                    $pageResults[] = $this->templating->getTemplating()->renderResponse(
                        'MauticPageBundle:SubscribedEvents\Search:global.html.php',
                        ['page' => $page]
                    )->getContent();
                }
                if (count($pages) > 5) {
                    $pageResults[] = $this->templating->getTemplating()->renderResponse(
                        'MauticPageBundle:SubscribedEvents\Search:global.html.php',
                        [
                            'showMore' => true,
                            'searchString' => $str,
                            'remaining' => (count($pages) - 5),
                        ]
                    )->getContent();
                }
                $pageResults['count'] = count($pages);
                $event->addResults('mautic.page.pages', $pageResults);
            }
        }
    }

```

and below is the code with my changes which fixes the issue.

```auto
public function onGlobalSearch(MauticEvents\GlobalSearchEvent $event)
    {
        $str = $event->getSearchString();
        if (empty($str)) {
            return;
        }

        $filter = ['string' => $str, 'force' => []];

        $permissions = $this->security->isGranted(
            ['page:pages:viewown', 'page:pages:viewother'],
            'RETURN_ARRAY'
        );
        if ($permissions['page:pages:viewown'] || $permissions['page:pages:viewother']) {
            if (!$permissions['page:pages:viewother']) {
                $filter['force'][] = [
                    'column' => 'IDENTITY(p.createdBy)',
                    'expr' => 'eq',
                    'value' => $this->userHelper->getUser()->getId(),
                ];
            }

            $pages = $this->pageModel->getEntities(
                [
                    'limit' => 5,
                    'filter' => $filter,
                ]);

            if (count($pages) > 0) {
                $pageResults = [];

                foreach ($pages as $page) {
                  / **my changes*** /
                  if(is_array($page)){
                    $page= $page[0];
                  }
                    $pageResults[] = $this->templating->getTemplating()->renderResponse(
                        'MauticPageBundle:SubscribedEvents\Search:global.html.php',
                        ['page' => $page]
                    )->getContent();
                }
                if (count($pages) > 5) {
                    $pageResults[] = $this->templating->getTemplating()->renderResponse(
                        'MauticPageBundle:SubscribedEvents\Search:global.html.php',
                        [
                            'showMore' => true,
                            'searchString' => $str,
                            'remaining' => (count($pages) - 5),
                        ]
                    )->getContent();
                }
                $pageResults['count'] = count($pages);
                $event->addResults('mautic.page.pages', $pageResults);
            }
        }
    }

```

so you can see I am checking if the $page is array it should get the 0 index and assign it to $page which fixes the issue.

To generate the issue you need to create a landing page and then use its name in global search input field and hit enter then open any other page in new tab. You will see 500 error on every new page that you will open as shown in below screenshot.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/9/91337e78e61f7070a4853c8b85616e604e19d0c5.jpeg)

---

<div class="post-metadata">

**Author:** ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)\
**Post date:** [September 17, 2023, 6:16pm UTC](https://forum.mautic.org/t/search-result-with-matching-landing-page-name-generating-fatal-error/29317/2 "2023-09-17T18:16:43Z")

</div>

It might be a bug, consider creating a PR on the github.
