This thread is resolved. Here is a description of the problem and solution.
Problem: You are experiencing a fatal error when using WP CLI commands with WPML and the Rollbar plugin due to a compatibility issue with the psr/log library. The error message indicates a declaration mismatch in
DebugFileLogger.php
. Solution: We recommend trying one of the following workarounds: 1) Disable the Rollbar plugin. 2) Modify the
DebugFileLogger.php
file in your WPML plugin directory. Replace its contents with the following code:>
<?php
namespace WPML\PHP\Logger;
use Psr\Log\AbstractLogger;
use Stringable;
class DebugFileLogger extends AbstractLogger {
public function log($level, Stringable|string $message, array $context = []): void {
if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) {
return;
}
$log = date( 'Y-m-d H:i:s' ) . ' [' . $level . '] ' . (string) $message . PHP_EOL;
\error_log( $log );
}
}
If these solutions do not resolve the issue or if they become outdated, please check for related known issues at https://wpml.org/known-issues/, verify the version of the permanent fix, and confirm that you have installed the latest versions of themes and plugins. If the problem persists, we highly recommend opening a new support ticket for further assistance.
This is the technical support forum for WPML - the multilingual WordPress plugin.
Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.
<b>Background of the issue: </b>
I am trying to use WP CLI to run the command:
wp rocket clean --confirm && wp rocket preload
This was in version 4.7.0, resolved by downgrading back to 4.6.15.
Seems to only be an issue with WP CLI, as admin interface is fine.
wp info
also has the same issue.
<b>Symptoms: </b>
I encountered a fatal error:
Fatal error: Declaration of WPML\PHP\Logger\DebugFileLogger::log($level, $message, array $context = []) must be compatible with Psr\Log\AbstractLogger::log($level, Stringable|string $message, array $context = []): void in /srv/www/{snip}/releases/20250210140815/web/app/plugins/wpml-multilingual-cms/vendor/wpml/wpml/lib/Php/Logger/DebugFileLogger.php on line 8. Error: There has been a critical error on this website.
Languages: English (English )Spanish (Español )German (Deutsch )
Timezone: Europe/Madrid (GMT+02:00)
Hi,
before your ticket is assigned to one of my colleagues, please allow me to walk you through some initial debugging steps. This will help speed up the support process.
Thanks for the details! I tested this locally using $ wp --info before and after activating WPML, but I couldn't reproduce the same error.
Could you please enable WP_DEBUG and check if any additional details appear in the debug log? Also, I noticed that your WP_MEMORY_LIMIT is currently set to 64MB, which is below our recommended minimum. While your server has 512MB available, the memory limit hasn’t been defined in wp-config.php yet. Please try increasing it and see if that resolves the issue.
Thank you Marcel, this is from my local testing, but I have increased WP_MEMORY_LIMIT to see if it makes a difference, and no.
Regarding the debug logs, the only entry contains pretty much what I posted earlier:
[10-Feb-2025 16:46:24 UTC] PHP Fatal error: Declaration of WPML\PHP\Logger\DebugFileLogger::log($level, $message, array $context = []) must be compatible with Psr\Log\AbstractLogger::log($level, Stringable|string $message, array $context = []): void in /Users/{snip}/Sites/{snip}/site/web/app/plugins/wpml-multilingual-cms/vendor/wpml/wpml/lib/Php/Logger/DebugFileLogger.php on line 8
Languages: English (English )Spanish (Español )German (Deutsch )
Timezone: Europe/Madrid (GMT+02:00)
Hi,
we were able to reproduce the issue with your installed "Rollbar" plugin, that loads another newer psr/log library than ours:
Workarounds:
1) Disable Rollbar
2) Adjust our code with this temporary solution:
Open wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wpml/lib/Php/Logger/DebugFileLogger.php and change it to this:
<?php
namespace WPML\PHP\Logger;
use Psr\Log\AbstractLogger;
use Stringable;
class DebugFileLogger extends AbstractLogger {
public function log($level, Stringable|string $message, array $context = []): void {
if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) {
return;
}
$log = date( 'Y-m-d H:i:s' ) . ' [' . $level . '] ' . (string) $message . PHP_EOL;
\error_log( $log );
}
}