Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

define $options as an array if its not already an array - the code is expecting an array. #15641

Conversation

chrislewis60
Copy link

@chrislewis60 chrislewis60 commented Apr 27, 2017

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.

Summary of Changes

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.

Testing Instructions

Just tested in the browser. No automated tests added.

Expected result

No 'Cannot use a scalar value warning' warnings

Actual result

Documentation Changes Required

None.

if (!is_array($options))
{
$options = array();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coding stylewise, I think you need to add a return after }.

@chrislewis60
Copy link
Author

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.

@mbabker
Copy link
Contributor

mbabker commented May 5, 2017

We need a proper test case for this and not just using review here. How is JHtml::stylesheet() being called that triggers the warning?

@Bakual
Copy link
Contributor

Bakual commented May 5, 2017

I also like Michael think we should find where the warning origins, because apparently there is code somewhere which calls that method wrong.

@polc1410
Copy link

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?

@Quy
Copy link
Contributor

Quy commented May 18, 2017

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.

@Bakual
Copy link
Contributor

Bakual commented May 18, 2017

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.

@polc1410
Copy link

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

@polc1410
Copy link

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

@wojsmol
Copy link
Contributor

wojsmol commented May 21, 2017

I have tested this item ✅ successfully on b34f620

code review


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

@Bakual
Copy link
Contributor

Bakual commented May 21, 2017

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.

@mbabker mbabker changed the title define $options as an array if its not already an array - the code is expecting an array. define $options as an array if its not already an array - the code is expecting an array. May 21, 2017
@Quy
Copy link
Contributor

Quy commented May 22, 2017

Here is a call from Joomlart's Elastica template in Joomla! 3.4.8:
$document->addStylesheet($url[1], $attrs['mime'], $attrs['media'], $attrs['attribs']);

@Bakual
Copy link
Contributor

Bakual commented May 22, 2017

@Quy That one is actually fine and still works. It has been deprecated with J3.7.0 and will not supported anymore with J4.0. Currently it logs a deprecation message if you use it that way.

@ghost
Copy link

ghost commented May 24, 2017

set Status on "Needs Review" cause of above Comment.


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

@Quy
Copy link
Contributor

Quy commented Oct 17, 2017

Can this be closed per @Bakual comment?

@joomla-cms-bot
Copy link

Set to "closed" on behalf of @franz-wohlkoenig by The JTracker Application at issues.joomla.org/joomla-cms/15641

@ghost
Copy link

ghost commented Oct 18, 2017

closed as stated above.


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

@chrislewis60
Copy link
Author

chrislewis60 commented Mar 27, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants