A loaded class is using the wrong version of (one of) its interface(s), which then causes program fatal error.
More specifically, I have included the Google API Client code in my component. This uses, and loads, the Monolog library.
The Google log client, as is standard, implements a LoggerInterface interface. Also as is standard it refers to the interface namespace simply as "Psr\Log\LoggerInterface".
use Psr\Log\LoggerInterface;
class Logger implements LoggerInterface, ResettableInterface { /* code */ }
At the point of trying to load the logger, I think there are two other instances of this same namespace loaded in my setup. One is (slightly) specific to my setup, being the AkeebaBackup instance, but the other is central to Joomla, the core version (at "libraries/vendor/psr/log/Psr/Log/LoggerInterface").
I'm not entirely sure of the process here because, tracing the code, it loads the Logger class with autoload and then seems to pass over the first interface, LoggerInterface, and shows trying to load the resettable interface. It manages this and then immediately goes to the fatal error code. It complains that the interface signature of the (emergency) method doesn't match the class implementation. The emergency method is declared as
public function emergency(string|\Stringable $message, array $context = []): void
which does match the instance supplied with the Google code. Both the other interface declarations in Joomla are older and are
public function emergency($message, array $context = []);
And thus the class load fails complaining
Compile Error: Declaration of Monolog\Logger::emergency(Stringable|string , array = []): void must be compatible with Psr\Log\LoggerInterface::emergency(, array = [])
Error message showing the fault.
Error 500, internal server error, complaining of faulty implementation of LoggerInterface class.
I have installed "vendor supplied code" into my custom component. I expect there are other ways to do it.
I wondered if changing the order of interface list on the logger class declaration might make a difference, putting LoggerInterface second. It doesn't.
I don't understand enough about php to know what's going on here.
Labels |
Added:
No Code Attached Yet
|
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-10-25 07:48:01 |
Closed_By | ⇒ | MarkRS-UK |
This is not the issue I thought it was. Definitely a problem, but neither a php nor Joomla issue.
Monolog (since that is the specific issue here) may be used in different packages but (usually) always with the same namespacing. Joomla's namespacing strategy avoids crashes but prevents the use of different versions.
Applying an extra step to change the problematic namespace(s), for example using php-scoper, overcomes the problem.