? Success

User tests: Successful: Unsuccessful:

avatar Bakual
Bakual
5 Feb 2014

Fixing the PHP warning

Creating default object from empty value in /.../libraries/cms/module/helper.php on line 164

if JModuleHelper::renderModule() is called without a proper module object.

avatar Bakual Bakual - open - 5 Feb 2014
avatar vdespa
vdespa - comment - 5 Feb 2014

If JModuleHelper::getModule() is faulty, I would rather fix that, as it promises to return a Module object and not null.

I would rather get some errors / warnings that could let me to the right fix.

avatar mbabker
mbabker - comment - 5 Feb 2014

renderModule() being a publicly accessible static method should do its own checks rather than assuming it's getting the correct data. So with that said, I might suggest two things:

1) getModule always returns a stdClass (instead of the default null it can return now)
2) renderModule checks that certain attributes are present in the object before it starts trying to render

avatar Bakual
Bakual - comment - 5 Feb 2014

If JModuleHelper::getModule() is faulty, I would rather fix that, as it promises to return a Module object and not null.

I don't think it's faulty. It either returns a module object, or null if it doesn't find anything. Returning an empty object doesn't make much sense imho. I wouldn't change that.
This way you can do a simple check if (JModuleHelper::getModule('blubb'))

renderModule checks that certain attributes are present in the object before it starts trying to render

Hmm, what would you check then?
Imho the check for an object is enoug as it will remove the warning. It's an issue which can happen as we found out today on developer.joomla.org :)
If the passed object doesn't have the right properties, it will show PHP notices, which I think is fine in this case. This case can only happen if a developer manually creates a faulty object and passes it to renderModule, it can't happen when he uses the API. I don't think we have to take care of that, or do we?

avatar mbabker
mbabker - comment - 5 Feb 2014

I'd just make it simple. If the module and params properties aren't present, log it and return null. To me, that's enough of a sanity check to ensure things we would expect to be in the object are there. Beyond that, if the developer is building the object manually, they should have a clue what they're injecting into the method (so copy what getModule returns).

BTW, I don't know how I did it, but I'm apparently pretty good at tabbing out of the editor here and submitting half complete comments :-D

avatar Bakual
Bakual - comment - 5 Feb 2014

Added checks for module and params properties and a logging.
I struggled a bit with JLog. If there is a simpler way, just say it :smile:

avatar infograf768 infograf768 - change - 13 Feb 2014
Status New Closed
Closed_Date 0000-00-00 00:00:00 2014-02-13 08:05:11
avatar infograf768 infograf768 - close - 13 Feb 2014
avatar infograf768 infograf768 - reference | 7d55d68 - 13 Feb 14
avatar infograf768 infograf768 - merge - 13 Feb 2014
avatar infograf768 infograf768 - close - 13 Feb 2014
avatar Bakual Bakual - head_ref_deleted - 24 Feb 2014
avatar Bakual Bakual - reference | 53bf50b - 12 May 14

Add a Comment

Login with GitHub to post a comment