User tests: Successful: Unsuccessful:
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.
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.
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
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?
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
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
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2014-02-13 08:05:11 |
Tracker: http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=33233