1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Call to a member function X on a non-object

Discussion in 'XenForo Development Discussions' started by Chris D, Oct 28, 2013.

  1. Chris D

    Chris D XenForo Developer Staff Member

    Given this code:
    PHP:
        public static function controllerPreDispatch(XenForo_Controller $controller$action)
        {
            
    self::$controllerName $controller->getRouteMatch()->getControllerName();
        }
    Which when executed by the Tapatalk mobile app, produces this error:

    Code:
    ErrorException: Fatal Error: Call to a member function getControllerName() on a non-object - library/AVForums/Banners/Listener.php:288
    Does the following seem like a reasonable solution?

    PHP:
        public static function controllerPreDispatch(XenForo_Controller $controller$action)
        {
            try
            {
                if (
    is_object($controller) && $controller instanceof XenForo_Controller)
                {
                    
    self::$controllerName $controller->getRouteMatch()->getControllerName();
                }
            }
            catch (
    Exception $e)
            {
                
    self::$controllerName '';
            }
        }
    Because, it doesn't work o_O

    Regardless of what conditionals I wrap around this line:

    PHP:
    self::$controllerName $controller->getRouteMatch()->getControllerName();
    Tapatalk always throws this error:

    Code:
    ErrorException: Fatal Error: Call to a member function getControllerName() on a non-object - library/AVForums/Banners/Listener.php:288
    Normal forum operation is fine. It's only a problem when we access the forum via the Tapatalk app.
     
  2. Daniel Hood

    Daniel Hood Well-Known Member

    PHP:
       public static function controllerPreDispatch(XenForo_Controller $controller$action)
    {
    try
    {
    if (
    is_object($controller) && $controller instanceof XenForo_Controller)
    {
    $routeMatch $controller->getRouteMatch();
    if (
    is_object($routeMatch) && $routeMatch instanceof XenForo_RouteMatch)
    {
    self::$controllerName $controller->getRouteMatch()->getControllerName();
    }
    }
    }
    catch (
    Exception $e)
    {
    self::$controllerName '';
    }
    }
    What's that do? Might not be getting a route match.

    [edit] Copying your code into the editor looks horrible, sorry.
     
  3. Chris D

    Chris D XenForo Developer Staff Member

    Awesome Daniel, that looks like it has worked.

    Thank you.

    :oops:
     
  4. Daniel Hood

    Daniel Hood Well-Known Member

    No problem. It's odd the routematch isn't there though...?
     
  5. Chris D

    Chris D XenForo Developer Staff Member

    It's all odd. It's Tapatalk :)

    Thanks again.
     
    Marcus and Daniel Hood like this.
  6. Stuart Wright

    Stuart Wright Well-Known Member

    @Chris Deeming, we are getting this error again. What do I do to fix it, please?
     
  7. Chris D

    Chris D XenForo Developer Staff Member

    Just sent you an updated version.

    My bad. It seems I didn't merge the changes I made with my local copy.
     
    Stuart Wright likes this.

Share This Page