PHP Version: 8.0
Module throws the following warnings:
PHP Deprecated: Required parameter $defaultLanguage follows optional parameter $prefix in /var/www/html/vendor/h5p/h5p-editor/h5peditor.class.php on line 376
Deprecated: Required parameter $defaultLanguage follows optional parameter $prefix in /var/www/html/vendor/h5p/h5p-editor/h5peditor.class.php on line 376
I checked the codebase of h5p-editor and this issue was already had a merged pull request:https://github.com/h5p/h5p-editor-php-library/pull/128, but it seems that the update to be compatible with PHP 8.0 was not yet included to version 1.24.4.
The patch I uploaded here was the update created in the main git repository of h5p-editor-php-library. So this patch will also the same update for the h5p-editor.
Proposed resolution
Create a patch to update h5p-editor to be PHP 8.0 compatible
Comments
Comment #2
sirclickalotLooks to me like this PR has been merged but I see no more recent alpha release and do official dev version release.
Am I mistaken?
Thanks all.
Comment #3
TamB commentedHi everyone,
Drupal 9.4 just got released yesterday with a minimum php compatibility of 7.4. That's the highest php version the h5p editor module can handle. As mentioned in #2, the compatibility issue does appear to have been resolved, but no up-to-date release has been issued for it yet.
This isn't a major problem as it seems sites can still function with php7.4 for a while. But, at least in my case, it would appear that php 8 compatibility for h5p editor is the only thing holding up an upgrade of my sites.
Would be grateful if a new release could be made soon for an otherwise awesome module.
Thanks!
Comment #4
sirclickalotAgreed 100%.
The H5P module is a crucial player in educational sites and come December it would be good to a void a scrabble to a compatibility fix.
Like Tam says, not crucial right now but why not deal with this plenty ahead of time?
Maintainers of this great module, a call to action ;-)
#Thanks
Comment #5
jackg102 commentedI can verify this issue when I upgraded my local environment to PHP 8. Tangibly speaking, how does this impact the H5P editor on an environment with PHP 8? I tested the editor, and it didn't seem to break after a cursory observation.
Acquia is ending support for PHP 7.4 October 3rd, so I'll throw my support in for resolving this ahead of schedule to avoid a scramble :-).
Comment #6
jakegibs617 commentedwould we not also want to re-arrange the params, since required now needs to be first with optional after:
Required parameter $defaultLanguage follows optional parameter
$prefix and $fileDir are optional params
public function getLibraryData($machineName, $majorVersion, $minorVersion, $languageCode, $defaultLanguage, $prefix = '', $fileDir = '')Comment #7
jakegibs617 commentedComment #8
jakegibs617 commentedComment #9
jakegibs617 commentedI found that Update_H5P-editor_PHP8_compatible_3260094_2.patch works for the initial error. But then I was getting an error with the vendor directory. In order to resolve the vendor error, I applied h5p-h5p-editor-h5peditor-class-php.patch
my composer.json file looks like this:
Comment #10
dianacastillo commentedget an error with the patch from #8
which i tried to apply like this :
this is the error :
patch number 7 alone works for me with php 8:
Comment #11
robcarrPatch at #8 won't apply. Patch at #7 does not address deprecation error in PHP 8.0.19
Comment #12
narendra.rajwar27For me, Patch at comment #7 fixes the issue for deprecation error message.
Drupal 9.5.x
PHP 8.0
Steps performed:
1- Using composer add module to project.
2- Go to any page in site, the error says:
deprecated: Required parameter $defaultLanguage follows optional parameter $prefix in /Users/narendra.rajwar/Documents/sites/contribution/drupal/vendor/h5p/h5p-editor/h5peditor.class.php on line 3763- Now enable the module using drush, the error says:
Comment #13
pixiekatThis one worked for me on the 2.0.0 branch.
Comment #14
pjotr.savitski commentedHere is the commit from the official repository that fixes said issue: https://github.com/h5p/h5p-editor-php-library/commit/2edfd9b9e72d20e3b61...
Below is an example taken from the composer.json file of a project (NB! Changed the previous faulty example):
The dependency itself already has a newer version, but current module is locked to the previous one. See this for more details.
NB! Patch #13 changes the signature of the method and can not really work. Yes, the deprecation warning will probably disappear, but the caller will still be passing the arguments in the previous order.
Comment #15
bob.hinrichs commentedI cannot figure out how to apply the patch above to the editor, because it seems to be added by the composer.json file in the module. Have tried some different things, some with errors and some seemingly apply it, but in the end it won't apply it, I think because it is loaded from the module's composer.json?
Would be nice to have a fix to these deprecation notices without having to struggle with patches to sub-components!
Comment #16
pjotr.savitski commented@bob.hinrichs It seems that I've removed too much from the copied part of the composer.json file. Will change the original comment to fix that. Below is the correctly working patches example.
Comment #17
bob.hinrichs commentedThank you Pjotr!
But this is the problem: h5p/h5p-editor is part of the drupal h5p module's composer packages and it installs into the module's own vendor directory. If I put "h5p/h5p-editor" into our composer file, it does not install h5p editor there. Is what we need a patch to patch the patches in the module? Or is there a need for a special installer-path (a pain)?
BTW
I am coming across another php 8 deprecation notice as well:
"Deprecated function: json_decode(): Passing null to parameter #1 ($json) of type string is deprecated in Drupal\h5peditor\H5PEditor\H5PEditorDrupalStorage->getLibraries() (line 130 of /app/web/modules/contrib/h5p/modules/h5peditor/src/H5PEditor/H5PEditorDrupalStorage.php)."
Comment #18
pjotr.savitski commented@bob.hinrichs It is a bit strange, but I do see that h5p-editor is installed into the root, so to say, vendor directory. That one is surely patched.
I'm not the best of the best composer specialist, but going through the H5P module code does give a hint on how it all really works. Please note that I'm using the 2.0.0 branch as that is what I have installed locally.
I read those lines as follows:
H5PCoreclass exists.You can clearly see that the local vendor catalog is part of the code repository and will be used if the modules are not managed using composer. It is possible to check why are the packaged dependencies being used and maybe even patch the H5P module to comment out or remove those lines. That is surely a bad decision as you should determine why are those sub-modules not installed. It does not matter that those are nit the top level dependencies as composer is not really installing anything into the h5p module and that one is just packaged with the module code itself. The dependencies of dependencies are evaluated by composer and installed as usual. There is
--with-all-dependencieskey, but that is mostly used when updating something.As for the deprecation warning you mentioned, well, that seems to be worse than just a deprecation warning. Do see the corresponding line for yourself.
That is the result of type hinting for arguments and it also affects the built-in functions. The value for
metadata_settingsis equal toNULLfor some of the libraries (I would even say most, at least that is what I currently see in my local instance). The line should be rewritten to something like this:$library->metadataSettings = !is_null($details->metadata_settings) ? json_decode($details->metadata_settings) : NULL;Hope that helps you enough to figure out what is wrong with your setup.
Comment #19
bob.hinrichs commentedThank you again! You made me see that I needed to delete the files in the already-installed vendor directory before running the revised install with h5p-editor in the main project vendor directory.
Also thank you for elaborating on that appears to be another fix necessary in this php 8 h5p editor ticket.
Comment #20
joelseguinI can confirm as well that applying the patches noted in #16 worked great.
Comment #21
TamB commentedPatch in #16 works for me as well! Whether this is the best long-term solution, I wouldn't be able to say.
Comment #22
rajab natshahFacing the same issue in PHP 8.0 and PHP 8.1
Comment #23
kenianbei commentedAny chance of getting this RTBC and commited soon? PHP 7.4 is EOL in January.
Comment #24
x775 commentedEchoing the question in #23.
Any updates would be much appreciated.
Comment #25
bob.hinrichs commentedI was having problems with this fix but had to edit my comment, I realized I was trying the patch linked in the issue but the actual patch is in #16.
Comment #26
scothiam commentedJust hit this issue trying to install the Opigno Distro. Looks like all has been resolved in Alpha3 less the "$defaultLanguage" issue.
Looks like this was solved in h5p-editor 1.25 by correcting $defaultLanguage as optional as well rather than changing the order:
On that note, maybe updating to h5p-editor 1.25 is the way to go? Again, I'm completely new to this module, that could be a very bad idea.
Free to test if need be. Let me know what to try. Thanks,
Comment #27
yuriy mykhalyna commentedI didn't see correct patch created here, so I created one myself. This patch works for me fine. Feel free to use.
Comment #28
PATED114 commentedHi all, I have created a new patch #28 for the latest version of h5p module for the compatibility of Drupal 10 compatibility.
Comment #29
ravimalviya2000 commentedHello Team,
I have same issues getting on my drupal project.I but i tried this patches but error not solved.
Comment #30
ragidikarthik7625 commentedUpdated patch for latest version of h5p.
Comment #31
igonzalez commented#30 works fine. Thanks
Comment #32
jorgewray93 commentedI have a problem applying the patch #30, for the structure of my project the patch can't be applied for that I take a different way creating a patch directly into the library and add the reference into my composer.json.
If you have the same issue do the next steps:
- Add the reference of your library directly in your composer
- Add my patch into the patch section
Comment #33
socialnicheguru commentedupdate:
There is confusion between h5p/vendor directory and the one managed in my install via composer.
I ended up going with what is outlined in #14 and applying the commits to the repo to h5p/h5p-editor library.
it got rid of this error:
Error: Optional parameter $fileDir declared before required parameter $defaultLanguage is
implicitly treated as a required parameter in
drupal9.5.9/vendor/h5p/h5p-editor/h5peditor.class.php,
line 376
drupal 9.5.9
php8.1
This was for another issue. I am sorry for the noise:
Workaround:not using the patch I added the following to my composer file
"h5p/h5p-core": "1.24.4 as 1.24.2",
"h5p/h5p-editor": "1.25 as 1.24.4",
Comment #34
papijo commentedCould someone please fix this annoying bug ASAP? Thanks!
Comment #35
ryan-l-robinson commentedPatch in #32 worked for me against the new Drupal 10 dev branch, PHP 8.1.
Comment #36
ammaletu commentedI just tried the current dev version of H5P with Drupal 10.1 and PHP 8.1 and got these deprecation notices. The patch from #32 fixes them.
Comment #37
catchThis needs to be fixed in https://github.com/h5p/h5p-editor-php-library if it's not already.
If the upstream library already has the fix, an MR to update the version would be good.
Comment #38
ammaletu commentedIt's fixed in the upstream version, see line 376 of: https://github.com/h5p/h5p-editor-php-library/blob/master/h5peditor.clas...
Comment #39
shaundychkoh5p/h5p-editor:1.25 supports PHP 8. Applying the patch at #3420268: Support h5p/h5p-core:1.26 and h5p/h5p-editor:1.25 updates the module to use version 1.25 of h5p-editor.