In an extension (possibly in Joomla code also) call JApplicationCms::getInstance()
without parameters.
Used to work in 3.6.5, now fails in 3.7.0 and 3.7.1
"Fatal error: Call to a member function get() on null in libraries/vendor/joomla/application/src/AbstractApplication.php on line 129"
I don't think anything is relevant with the level of informations I give bellow
The related changes 3.6.5 -> 3.7.0 are in libraries/legacy/application/application.php->_createSession
which now calls $this->get('force_ssl')
instead of $this->getCfg('force_ssl')
. The function getCfg()
calls JFactory::getConfig()
but AbstractApplication->get()
uses a protected object which is (I don't know why) not initialized at the moment which I call JApplicationCms::getInstance()
.
I fixed my extension by using JApplicationCms::getInstance('site')
but since the parameter $name is optional, other 3rd party extensions might call it without parameters and crash as mine.
Category | ⇒ | Libraries |
I'd need a stack trace. There shouldn't be a path where the app config
object isn't initialized. Also, nothing in core should really be going
through legacy JApplication at this point, and the way we coded the app
migration most extensions shouldn't be either.
The only time JApplicationCms::getInstance needs an argument is if that's
the first call to the method. I get the feeling to reach a path where you
need a parameter, we're talking about something on the command line or a
custom web app at this point. Joomla's 3 apps (site, admin, and install)
all handle this initialization too early in the request for an extension to
have that issue.
On Fri, May 19, 2017 at 1:40 PM Phil Taylor notifications@github.com
wrote:
if this is deep in _createSession then @mbabker
https://github.com/mbabker might be one most educated to answer here
without me debugging deep in the code - he could probably answer this off
the top of his head. He is more intelligent, younger and has more hair than
I do... although I have two working knees :) ?—
You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub
#16085 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAWfoWVs5JaMHaP5EaHY3bBLQdgrFJLEks5r7eICgaJpZM4Nd_V2
.
--
Status | New | ⇒ | Discussion |
I can toggle this error by adding/removing JApplicationCms::getInstance()
to my template's index.php
. The error disappears when I use JApplicationCms::getInstance('site')
instead. I was using Joomla 3.7.2.
Nothing about getInstance()
has changed since the class was introduced in 3.2. So it should have always had issues with having a null value (and that's just an API mess up on our behalf). It seems like passing a null there might be trying to instantiate JApplication
, which is a different class chain than JApplicationCms
and wouldn't match the documented return here.
So in 4.0, we need to make the name param required. As for the current problem with passing null, if someone can confirm that doing so ends up in a JApplication
instance being instantiated, that would be useful to know what to debug.
Nothing has changed? I added the call to my template months ago and it run well with 3.6. The error first turned up when I upgraded to 3.7.2 today (from 3.6 or so).
getInstance()
hasn't changed. As the original post notes, it looks to be a change in the deprecated (and generally unused now) JApplication
class that's causing problems. The fact that getInstance()
accepted a null value though is a major design flaw as that method doesn't have a singleton instance in front of it and the null value causes an object that doesn't match the API documentation to be returned.
If you just need the active application, use JFactory::getApplication()
. If you need a specific application, use JApplicationCms::getInstance()
with a parameter, but do not rely on JApplicationCms::getInstance()
with a null parameter because it is quite frankly wrong and that method shouldn't have been accepted in the way it is now.
Status | Discussion | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2017-08-18 20:02:13 |
Closed_By | ⇒ | brianteeman |
if this is deep in _createSession then @mbabker might be one most educated to answer here without me debugging deep in the code - he could probably answer this off the top of his head. He is more intelligent, younger and has more hair than I do... although I have two working knees :) ?