User tests: Successful: Unsuccessful:
Pull Request relating to Issue #15548 and #15600.
'stylesheet' function in /libraries/cms/html/html.php takes an $options which may or may not be an array. After upgrading to Joomla 3.7 I was seeing 'Cannot use a scalar value warning' warnings displayed in the frontend website relating to lines 620, 621, 622 and 623. There have been some changes to this function in the last couple of days - I don't know whether there has been an unintended consequence as a result.
In the section that produced warnings, the $options variable is expected to be an array. I've added a check to say that if it's not an array then define it as an empty array. If it is already an array then there is no impact. The code is expecting it to be an array.
Just tested in the browser. No automated tests added.
No 'Cannot use a scalar value warning' warnings
None.
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
We need a proper test case for this and not just using review here. How is JHtml::stylesheet()
being called that triggers the warning?
I also like Michael think we should find where the warning origins, because apparently there is code somewhere which calls that method wrong.
I'm getting this issue appearing following a 3.6.5 to 3.7.1 upgrade.
I can obviously patch the file but:
(a) what do we need to do to get that into 3.7.2
(b) do you want me to try and isolate what calls the code in the firt place?
a) submit a pr
b) Yes per Bakual:
I also like Michael think we should find where the warning origins, because apparently there is code somewhere which calls that method wrong.
do you want me to try and isolate what calls the code in the firt place?
Yep, that would be very interesting if you can get that information.
OK. So I've traced the issue to three calls to style sheets:
1. https://{mydomain-removed}/administrator/components/com_joooid/views/configuration/tmpl/joooidcontent.css $options = 1
Joooid is an extension (http://www.joooid.com), and disabling its plugin called:
Joooid Content stops it generating issues. Line 43 of its file: "joooidcontent.php" is currently:
JHtml::stylesheet(JUri::base() . 'administrator/components/com_joooid/views/configuration/tmpl/joooidcontent.css', true);
Updating this to:
$options = array(); $attribs=(); JHtml::stylesheet(JUri::base() . 'administrator/components/com_joooid/views/configuration/tmpl/joooidcontent.css', $options,$attribs, true);
Resolves the issue. I've raised a bug report with joooid although not sure if/when they will fix as v2.6 hasn't had any updates since 2015.
2. tooltips/style.min.css $options was empty
Tooltips is a plugin.
This was a grossly out dated version (v3.7.9 now on 7.0.9) - I haven't been able to update it yet as I need to increase my PHP version. Will post an update on that once I know more.
3. $file was empty but $options contained: "templates/system/css/system.css"
I haven't yet found what is going on with this. Will post back on that shortly
OK now found source for 3 is JA Elastica Template: file /templates/ja_elastica/blocks/head.php lines #32 and 33
`
Bug report here: https://www.joomlart.com/forums/topic/joomla-3-7-update-status/page/8/#post-1035193
So I don't think there is a fault in the core calling the function, but there is clearly a number of "dodgy" calls in older code. SO I think putting the fix in would make sense. But with a depreciation error
I have tested this item
code review
I tend to say this PR isn't something we should do, as it is only a bandaid for faulty code in 3rd party extensions. It should be fixed in the respective extensions.
If we're going to do something like this, then it has to be deprecated right away with at least a log message. But then, the current warning is fine as the code still works and the extension developer gets notified of his faulty code right away. On productive servers, those warnings should be disabled anyway.
Rel_Number | ⇒ | 15548 | |
Relation Type | ⇒ | Pull Request for |
Title |
|
Here is a call from Joomlart's Elastica template in Joomla! 3.4.8:
$document->addStylesheet($url[1], $attrs['mime'], $attrs['media'], $attrs['attribs']);
Status | Pending | ⇒ | Needs Review |
set Status on "Needs Review" cause of above Comment.
Status | Needs Review | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2017-10-18 05:52:25 |
Closed_By | ⇒ | franz-wohlkoenig |
Closed_By | franz-wohlkoenig | ⇒ | joomla-cms-bot |
closed as stated above.
Set to "closed" on behalf of @franz-wohlkoenig by The JTracker Application at issues.joomla.org/joomla-cms/15641
Many months later I actually discovered that it was the Joooid plugin that http://www.joooid.com/ that caused this issue. Once disabled the warnings went away. It may have been updated now but if anyone sees this issue again, try disabling the Joooid plugin.
I don't know whether adding a return directly after } is a safe thing to do - there are lines below it (624-627) that may still need to be executed. My amend is simply ensuring that $options is an Array before it gets to the code below it so that the warnings about it not being an array are suppressed. I don't know if there are any knock on consequences of this amend - I just know that in my installation it was the only way that I found to suppress the frontend warnings without breaking the admin area as well.