If $library['version callback']
uses a pass by reference parameter (and does not have $library['version arguments'][0]>
set, then a warning is thrown in a PHP 7.0 environment. Issue can cause referenced library not to load correctly. This was specifically seen with the Navbar module which used the function _navbar_libraries_get_version(&$library, $options = array())
.
Example of the error:
Warning: Parameter 1 to _navbar_libraries_get_version() expected to be a reference, value given in libraries_detect() (line 549 of libraries.module).
That particular line uses call_user_func()
which only passes parameters by value and never by reference. It needs to be changed to call_user_func_array()
, which is actually used as the other version callback
function for a slightly different branch scenario.
Bug was seen originally in 7.x-2.3. Verified bug still exists in 7.x-2.x-dev.
Comment | File | Size | Author |
---|---|---|---|
#11 | libraries-version-callback-reference-parameter-fix-2779591-11.patch | 683 bytes | mark_fullmer |
Comments
Comment #2
cglauren CreditAttribution: cglauren commentedComment #3
cglauren CreditAttribution: cglauren commentedComment #4
tstoecklerThis is definitely a feature request. Version callbacks currently have one - and only one - purpose: Return a version. They are not allowed to modify the library at the moment. I.e. the fix would be removing the ampersand in the function declaration of Navbar module. Can you elaborate on the use-case for this?
On the other hand, this looks very harmless. I see no reason not to commit this. Sending for a test run for now.
This might also be a nice way to fix #2167249: Make version/variant callbacks provide error messages themselves for better DX/UX. without breaking BC, if we add some docs that say that version callbacks should populate
$library['error message']
or something like that.Comment #5
Ace Cooper CreditAttribution: Ace Cooper as a volunteer commented@cglauren Thank you! This patch just saved me a lot of grey hair.
I was checking out the QuickEdit module, so I installed both JS dependecies:
backbone/backbone-min.js
andunderscore/underscore-min.js
into thelibraries
folder. But for the life of me I couldn't get their versions to show up on the Status page, instead receiving the status:I repeatedly checked if
backbone/underscore
versions mismatched the prerequisites.Then I though that maybe my
libraries
orjquery_update
version could be wrong.I also noticed a couple of these errors in my watchdog:
Warning: Parameter 1 to _quickedit_libraries_get_version() expected to be a reference, value given in libraries_detect() (line 556 of /sites/all/modules/libraries/libraries.module)
A short search landed me here and luckily this patch #3 fixed the problem.
Now both Backbone 1.3.3 and Underscore 1.8.3 are detected correctly.
Comment #6
robertgarrigos CreditAttribution: robertgarrigos commentedThis patch fixed it for me also.
Comment #7
maximpodorov CreditAttribution: maximpodorov commentedThe patch works perfectly.
Comment #8
mark_fullmerI can confirm the patch works on PHP 7.1.1 as well. The patch in #3 however, does not apply against the latest version of 7.x-2.x-dev. Re-roll attached.
Comment #10
mark_fullmerPatch re-rolled with proper diff directories.
Comment #11
mark_fullmerThird time's the charm.
Comment #12
svenryen CreditAttribution: svenryen commentedReviewed and tested. It would be nice to get this added to the next release :)
Comment #13
szeidler CreditAttribution: szeidler at Ramsalt Lab commentedI haven't verified why the navbar module uses this unconventional approach, but I can confirm, that the patch #11 is fixing the issue in my PHP 7.1 environment.
Comment #14
efpapado CreditAttribution: efpapado at Ramsalt Lab commented+1 RTBC, please commit.
Comment #15
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedTested with PHP 7.1.9, patch works as advertised.
RTBC++
Comment #16
caminadaf CreditAttribution: caminadaf at CI&T for Pfizer, Inc. commented+1 RTBC tested with PHP 7.1.8
Comment #17
dscl CreditAttribution: dscl at DevBrains commented+1 RTBC
Tested on 7.1.13.
Unassigned it considering the work is done and nobody is actually working on it.
It would be great to see it committed! :)
Comment #18
bkosborne+1 RTBC. Unfortunately the last commit to the 7.x branch was nearly 1.5 years ago =/
Hopefully we can get the attention of a maintainer to get this committed.
Comment #19
joseph.olstadHello, can someone please take over maintainership of this project and publish a release with this fix?
Here is how:
Then @dddave will evaluate and likely grant you maintainership, then you will be able to commit this patch and tag and publish a release.
https://www.drupal.org/project/projectownership
For clarification, review this page https://www.drupal.org/project/projectownership
Comment #20
osopolar#11 works for me too.
Comment #21
Kris77 CreditAttribution: Kris77 commentedPatch #11 work for me too with Drupal 7.59 and PHP 7.1
Thanks to @mark_fullmer.
Comment #22
nikolabintev CreditAttribution: nikolabintev commented#11 works for me with D7.59 and PHP 7.1
Comment #23
joseph.olstadOK thanks I am now a maintainer of libraries please ping me to remind me to commit this and publish a release if I have not done so by Oct 1st
Also, If there is some other important patch we need for this coming release let me know asap. If you want to help please create a release plan issue and link to this and other suggested patches for the release.
Comment #25
joseph.olstadLibraries 7.x-2.4 has been tagged and released.
To thank me, I ask each of you to become a maintainer of at least one module on Drupal.org (if not already a maintainer).
Here is how to become a maintainer:
Then @dddave will evaluate and likely grant you maintainership, then you will be able to commit this patch and tag and publish a release.
https://www.drupal.org/project/projectownership
For clarification, review this page https://www.drupal.org/project/projectownership
Thanks everyone!
Comment #26
sjerdo@joseph.olstad
Seems like this issue is not included in CHANGELOG.txt.
Comment #27
joseph.olstadit's in the release notes. see here: https://www.drupal.org/project/libraries/releases/7.x-2.4
CHANGELOG.txt is a throwback to the days of CVS. If you want to become a co-maintainer feel free to do so and update it.
Now with git, all the history is available in all the clones.