Try to use:
JFactory::getDocument->addStyleSheetVersion('my.css', $version='3.1.1');
JFactory::getDocument->addStyleSheetVersion('my.js', $version='3.1.1');
CSS and JS files will be added to the page, together their version string
J3.6.x: It works
Staging: Partly broken
Warning: Illegal string offset 'version' in deve/joomla-cms/libraries/joomla/document/document.php on line 550
Warning: Illegal string offset 'version' in devel/joomla-cms/libraries/joomla/document/document.php on line 741
J3.6.x signatures
public function addStyleSheetVersion($url, $version = null, $type = "text/css", $media = null, $attribs = array())
public function addScriptVersion($url, $version = null, $type = "text/javascript", $defer = false, $async = false)
J3.7.x signatures
public function addStyleSheetVersion($url, $options = array(), $attribs = array())
public function addScriptVersion($url, $options = array(), $attribs = array())
At minimum the existing code of calling the method with the old way needs to work,
and there should be no PHP warnings
It should not be too difficult to detect the old way of calling the methods, and make them work
Also, in the rare case that someone both extends the JDocument, and also overrides the 2 methods, there will be some PHP warnings
Labels |
Added:
?
|
Title |
|
Title |
|
Title |
|
Also for the case of B/C of someone extending JDocument and redeclaring the methods:
addStyleSheet, addStyleSheetVersion
addScriptVersion, addScriptVersionVersion
Notes:
To summarize, $options and $attribs need their old defaults to stay compatible
addStyleSheet($url, $options = array(), $attribs = array())
addStyleSheetVersion($url, $options = array(), $attribs = array())
addScriptVersion($url, $options = array(), $attribs = array())
addScriptVersionVersion($url, $options = array(), $attribs = array())
[EDIT]
The "compatiblity" way of using the methods, should be documented in the code (and in official documentation), now the code handles old way of calling, but does not document the previous signature
@ggppdk i can try and solve the warning issues - it's obvious a bug.
Reggarding potential B/C issues with the change with method signatures in all 6 methods (they were changed in JHtml too), i asked to check B/C policy in the first PR that proposed this change in method signatures (#11289).
If that are B/C problems in those PR they need all to be reverted.
For info, the sequence of PR that made this changes are:
Also all the merged PR that use this new PR method signatures would need to be corrected..
All all the js polyfill changes and all the PR that do inline js changes to use this new ie conditional option would needs to be changed/reverted.
(and probably more PR that i can't remember now)
So we need to be sure this is a B/C issue. PLT please advice.
Besides the small bug (wrong IF check, that is easy to fix)
the only B/C issue that might be a problem (or it may not be, are the default values) of the methods
i was confused with declaration of type for method parameters, which is not our case
i will test now
I am sorry i was confused with declaration for variable types for method parameters,
which is not our case
I tested, no B/C break
Only the bug with PHP warning,
caused by the wrong IF check, needs to be fixed
if (!is_array($options) && !is_array($attribs))
Something like this should be enough:
if (!is_array($options))
np, will check that when i have time
@ggppdk i'm now looking with tiume to your PR description.
you are making this:
JFactory::getDocument->addStyleSheetVersion('my.css', $version='3.1.1');
JFactory::getDocument->addStyleSheetVersion('my.js', $version='3.1.1');
when it should be this:
JFactory::getDocument()->addStyleSheetVersion('my.css', '3.1.1');
JFactory::getDocument()->addScriptVersion('my.js', '3.1.1');
But yes, the issue exists
Closing since we have a PR to test for it.
Thanks
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-11-08 12:17:32 |
Closed_By | ⇒ | jeckodevelopment |
Using $version='3.1.1',
is irrelevant, it is about readability and about avoid bugs
I usually do not use this, when only having 2 or 3 parameters
but for more i do for 3+ parameters
Otherwise the performance difference due to the redudant variable declaration is non-measurable,
and probably PHP compiler, will disgard the variable declaration it completely
Example of readability, and avoiding mistakes:
$send_result = JFactory::getMailer()->sendMail(
$_from = $data['mailfrom'], $_fromName= $data['fromname'], $_recipient = array($email),
$_emailSubject, $_emailBody,
$_html_mode=true, $_cc=null, $_bcc=null, $_attachment=null,
$_replyto='some@sommmmmm.org', $_replytoname=null
);
You could of course declare the variables above the method call, but this means a few extra lines
sure please test the PR
doing already, thanks !
I looked at the code in the
@andrepereiradasilva
if (!is_array($options) && !is_array($attribs))
should probably be: (in all 4 methods)
if (!is_array($options) || !is_array($attribs))