?
avatar pgassmann
pgassmann
7 Feb 2016

Error

Following error occurs on every page after Joomla-Upgrade from 3.4.8 to 3.5.0-beta2:

with php5:

Call to a member function getAuthorisedViewLevels() on a non-object in menu.php

with php7.0, with stacktrace:

Fatal error:  Uncaught Error: Call to a member function getAuthorisedViewLevels() on null in /var/www/joomla/libraries/cms/menu/menu.php:356
Stack trace:
#0 /var/www/joomla/libraries/cms/application/site.php(82): JMenu->authorise(101)
#1 /var/www/joomla/libraries/cms/application/site.php(766): JApplicationSite->authorise(101)
#2 /var/www/joomla/libraries/cms/application/site.php(215): JApplicationSite->route()
#3 /var/www/joomla/libraries/cms/application/cms.php(257): JApplicationSite->doExecute()
#4 /var/www/joomla/index.php(49): JApplicationCms->execute()
#5 {main}
  thrown in /var/www/joomla/libraries/cms/menu/menu.php on line 356

Source:

https://github.com/joomla/joomla-cms/blob/staging/libraries/cms/menu/menu.php#L356

        /**
         * Method to check JMenu object authorization against an access control
         * object and optionally an access extension object
         *
         * @param   integer  $id  The menu id
         *
         * @return  boolean  True if authorised
         *
         * @since   1.5
         */
        public function authorise($id)
        {
                $menu = $this->getItem($id);

                if ($menu)
                {
                        return in_array((int) $menu->access, $this->user->getAuthorisedViewLevels());
                }

                return true;
        }

Findings / Workaround

$this->user is not defined. This object is actually defined in the __construct() method

To workaround the issue, I copied the line from the constructor and added it before getAuthorisedViewLevels() is called in the authorise() method

                        $this->user = isset($options['user']) && $options['user'] instanceof JUser ? $options['user'] : JFactory::getUser();
                        return in_array((int) $menu->access, $this->user->getAuthorisedViewLevels());
avatar pgassmann pgassmann - open - 7 Feb 2016
avatar pgassmann pgassmann - change - 7 Feb 2016
Title
getAuthorisedViewLevels() on non-object/null in menu.php $this->user not initialized
getAuthorisedViewLevels() on non-object/null in menu.php with 3.5-beta2
avatar brianteeman brianteeman - change - 24 Feb 2016
Labels Added: ?
avatar brianteeman
brianteeman - comment - 1 Mar 2016

Can you please test again with Beta 3


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9081.

avatar brianteeman brianteeman - change - 1 Mar 2016
Category ACL
avatar brianteeman brianteeman - change - 1 Mar 2016
Status New Information Required
avatar pgassmann
pgassmann - comment - 1 Mar 2016

It is still exactly the same error.

The calls in the stacktrace are all in the core. Could still an override from a Template trigger this? Where should I look?

avatar brianteeman
brianteeman - comment - 10 Mar 2016

Easy way to see if it is something in the template is to switch to one of the core templates (protostar) and see if the error is present


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9081.

avatar pgassmann
pgassmann - comment - 10 Mar 2016

It is not the template.
It could be in a Plugin. But shouldn't it then be somehow in the call stack?

avatar ggppdk
ggppdk - comment - 10 Mar 2016

No it does not need to appear in the call stack

It looks like (i am only guessing)
that you have a plugin that is overriding JMenuSite (it does not override JMenu instead it overrides JMenuSite and extends JMenu)

  • the constructor of JMenuSite that comes with Joomla does call the parent constructor, thus $this->user is assigned,

if the overriden JMenuSite extends JMenu but it does not call the parent constructor then in this case you will get this error

you can try these:

  • with a text editor tool do a recursive directory text search in joomla root folder for *.php files:
    class JMenuSite
    thus you will see if there is such a plugin

  • adding some code to the constructor of JMenuSite to see if it is really called :
    echo "<pre>"; debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); echo "</pre>";
    file is: libraries/cms/menu/site.php

  • but maybe better is adding this to see where JMenuSite was defined:

$reflector = new ReflectionClass('JMenuSite');
echo $reflector->getFileName();

add it above just above:
return in_array((int) $menu->access, $this->user->getAuthorisedViewLevels());

and if you find then report to the developer

avatar pgassmann
pgassmann - comment - 26 Mar 2016

Thank you.

The problem is in the Joomfish Plugin. In the file plugins/system/jfoverrides/classes32/menu.php, the parent constructor is not called and $this->user is not set.

    /**
     * Class constructor
     *
     * @param   array  $options  An array of configuration options.
     *
     * @since   1.5
     */
    public function __construct($options = array())
    {
        static $params = array();
        // Load the menu items
        $this->load();

        foreach ($this->_items as $item)
        {
            if ($item->home)
            {
                $this->_default[trim($item->language)] = $item->id;
            }

            $pkey = md5($item->params);

            if (!isset($params[$pkey]))
            {
                // Decode the item params
                $result = new JRegistry;
                $result->loadString($item->params);
                $params[$pkey] = $result;
            }

            $item->params = $params[$pkey];
        }
    }

Fix: add the line $this->user = ... from libraries/cms/menu/site.php

[...]
                $params[$pkey] = $result;
            }

        $this->user = isset($options['user']) && $options['user'] instanceof JUser ? $options['user'] : JFactory::getUser();
}
avatar pgassmann pgassmann - change - 26 Mar 2016
Status Information Required Closed
Closed_Date 0000-00-00 00:00:00 2016-03-26 14:45:44
Closed_By pgassmann
avatar pgassmann pgassmann - close - 26 Mar 2016
avatar stemithy
stemithy - comment - 17 Jul 2017

Thank you! I had an issue with Joom/LanternFish on Joomla 3.7.3 using PHP 7.0.21 and the jfoverrides hack worked.

Add a Comment

Login with GitHub to post a comment