I get the following error when trying to use mpdf:
Declaration of MpdfMpdf::setLogger(PsrLogLoggerInterface $logger)
must be compatible with PsrLogLoggerAwareInterface::setLogger(PsrLogLoggerInterface $logger): void
The most information I can find on the topic is this but I can’t find how to fix it.
There is mention of using the branch php8-support
but I tried this and it doesn’t work either.
Has anyone found a work around on this?
I am on php 8.1.12
and using "mpdf/mpdf": "v8.0.13"
2
Answers
Versions and branches of mPDF have nothing to do with this.
mPDF is not compatible with
psr/log
3.x
because of support of older PHP versions (which do not have return type hints).One or more of your dependencies, or yourself, are forcing
psr/log
library to version3.x
. You can find out which by callingcomposer why psr/log
in the console.Downgrade the
psr/log
library to2.x
– just enter/change"psr/log": "^2.0"
line in your composer.json file and runcomposer update
. This should resolve the issue.If any of your libraries enforce
psr/log
3.x
(do not allow lower major versions), thecomposer update
call will fail and you will have to either downgrade or replace these libraries, or not use mPDF.Downgrade psr/log from 3.x is not a good idead and involve security risk. It may create conflict with other packages which require newer psr/log.
Mpdf v8.0.16 support psr 3.0, install it first.
Then go to vendor/psr/log/src/LoggerAwareInterface.php
Change from:
Change to:
This change will solve your issue.
Note:It is only minor change and not having big influence. If you keep on using psr/log v2, you can downgrade and all of your package must use psr/log v2 for consistence. If you want using psr/log v3, making change in vendor folder is the only choice because setlogger in mpdf is not compatible with setlogger in LoggerAwareInterface. It’s common practice that change should not be made in vendor file and keep on using psr/log v2 is better choice.