Problem/Motivation
This issue I believe is after this update: https://git.drupalcode.org/project/drupal/commit/c8cc155#9013c0bcc39d0f1...
I ran into an issue after upgrading to Drupal 9.1.0, and attempting to run drush cr -y using PHP 7.3.9.
It also happens with drush st and probably all drush commands.
he issue is that two class methods updated in Drupal 9.1.0 are lacking the type hint string that the interface has in the declaration.
- \Drupal\Core\ProxyClass\File\MimeType\ExtensionMimeTypeGuesser::guessMimeType($path)
- \Drupal\Core\File\MimeType\MimeTypeGuesser::guessMimeType($path)
They should be updated to match the interface \Symfony\Component\Mime\MimeTypeGuesserInterface::guessMimeType(string $path): ?string
Without this running drush commands you get a PHP fatal error:
PHP Fatal error: Declaration of Drupal\Core\ProxyClass\File\MimeType\ExtensionMimeTypeGuesser::guessMimeType($path): string must be compatible with Symfony\Component\Mime\MimeTypeGuesserInterface::guessMimeType(string $path): ?string in /Users/nathanandersen/dev/mdb/web/core/lib/Drupal/Core/ProxyClass/File/MimeType/ExtensionMimeTypeGuesser.php on line 15
and
PHP Fatal error: Declaration of Drupal\Core\File\MimeType\MimeTypeGuesser::guessMimeType($path): ?string must be compatible with Symfony\Component\Mime\MimeTypeGuesserInterface::guessMimeType(string $path): ?string in /Users/nathanandersen/dev/mdb/web/core/lib/Drupal/Core/File/MimeType/MimeTypeGuesser.php on line 14
[warning] Drush command terminated abnormally.
Steps to reproduce
For me, it was updating to Drupal 9.1.0 using PHP 7.3.9.
The code was updated recently in 9.1.0: #3055193: [Symfony 5] The "Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser" class is deprecated since Symfony 4.3, use "Symfony\Component\Mime\MimeTypes" instead.
Proposed resolution
add "string" declaration.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #28 | 3190265-28.patch | 1.27 KB | pieterdc |
| #2 | 3190265-2.patch | 1.28 KB | oknate |
Comments
Comment #2
oknateThis patch fixes the issue for me.
Comment #3
oknateComment #4
oknateComment #5
oknateComment #6
oknateComment #7
larowlanAre you using drupal/core-recommended?
It could be your symfony version is greater than ours
Comment #8
oknateI'm not using drupal/core-recommended. Is that the way I should be doing it, instead of using drupal/core directly?
My version of symfony/mime is v5.1.2.
drupal/core-recommended has
"symfony/mime": "v5.1.8",
https://github.com/drupal/core-recommended/blob/9.1.0/composer.json
The code looks the same for the interface in these two versions:
https://github.com/symfony/mime/blob/v5.1.2/MimeTypeGuesserInterface.php
https://github.com/symfony/mime/blob/v5.1.8/MimeTypeGuesserInterface.php
It has the string type declaration, while the core methods that implement it does not.
Comment #9
oknateI switched to use drupal/core-recommended (9.1.0 tag) and the same error occurs (without the patch).
Comment #10
larowlanThanks, sounds like an issue then
Comment #11
larowlanComment #12
oknateNote:
Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser has the correct implementation:
public function guessMimeType(string $path): ?string {So Drupal\Core\File\MimeType\MimeTypeGuesser which also implements the interface not adding the type hint "string" in the ::guessMimeType declaration is inconsistent.
The same goes for Drupal\Core\ProxyClass\File\MimeType\MimeTypeGuesser.
Comment #13
oknateComment #14
_kom__ commentedI had the same issue after attempt to deploy on production site (SSH-console running under PHP 7.3.10) after update from Drupal 9.0.9 to 9.1.2 and trying to 'drush updb'. There was no such error on local machine under PHP 7.4.9.
Is it due to PHP version running Drush? Will update to 7.4 help?
Comment #15
_kom__ commentedAfter update to PHP 7.4.10 version in CLI on production server I've got the same error. Reverting back to D9.0.9. Waiting for applying patch in D9.1 branch.
(It is interesting that I don't see this bug on local machine: its configuration is almost the same as remote production server).
Comment #16
_kom__ commentedI have 5.1.0 version of symfony/mime in my drupal/core-recommended version 9.0.9. It also contains "string" declaration and there was no such error when I had updated to 9.0.9.
Comment #17
oknateComment #18
oknateComment #19
_kom__ commentedThis patch works well for me.
With a small notice: I've had to downgrade PHP version in CLI and Drush startup from 7.4.10 to 7.3.23. Otherwise drush updb starts normally, gives a list of pending updates, but then - there is a lot of errors related to Drush:
In ProcessBase.php line 171: Unable to decode output into JSON: Syntax error Error: Call to a member function claimItem() on null in _drush_batch_worker () (line 237 of /home/c/******/vendor/drush/drush/includes/batch.inc) and so onI think that it is due to complicated relationships between Drush 10.3.6, PHP 7.4 and Drupal 9.1. Something keeps going wrong.
Nevertheless, RTBC +1.
Comment #21
damienmckennaJust hit this with the Backup Migrate tests: https://www.drupal.org/pift-ci-job/2085911
Comment #22
damienmckennaFWIW the tests run against PHP 7.1, MySQL 5.5 and Drupal 9.1.x.
Comment #23
longwaveAre we sure #2 fully fixes the issue? There is a subtle difference in the proxy class:
vs
ie. the proxy class is missing the question mark that indicates a nullable return type.
Comment #24
longwaveIf I change the base class only and then rerun the generate-proxy-class.php script as indicated at the top of the file it does add the nullable return type.
Nullable types for proxy classes was fixed in #3156944: Support nullable typehints and return types in ProxyBuilder and as a result support PHP 8 but somehow this difference was missed at that time.
Comment #26
simon.fryer commentedDon't know if this helps anyone, but I hit this issue trying to run `drush updb`, but, in particular, and exactly, by calling the PHP 7.4 binary directly because I was on a shared UAT server with multiple PHP versions through EasyApache.
In the end because my local was not experience any issues matching the exact versions of everything, even down to the exact minor PHP release, I set the default php to 7.4 and remove the call to the 7.4 binary, and the same command that had been failing for a few days, now works.
Unsure why, but that solved my issue without doing anything else.
Comment #28
pieterdcLooks like this issue got partially fixed by #3055193: [Symfony 5] The "Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser" class is deprecated since Symfony 4.3, use "Symfony\Component\Mime\MimeTypes" instead. meanwhile.
But it still lacks the same fix, as pointed out in comment #23, in a similar place, at least in Drupal 9.4
See patch attached.
Comment #31
joegraduateLooks like the proxy classes were fixed with #3197482: Update Drupal 10 to depend on Symfony 5.4 (as a stepping stone to Symfony 6, for deprecation checking support).