Drupal 11.2.2. PHP 8.4:

In PHP 8.4 nullable values in functions has changed.
One example (modules\contrib\backup_migrate\src\Entity\WrapperEntityBase.php):
public function access($operation, AccountInterface $account = NULL, $return_as_object = FALSE) {
Should be:

  public function access($operation, ?AccountInterface $account = NULL, $return_as_object = FALSE) {

OR
public function access($operation, AccountInterface|null $account = NULL, $return_as_object = FALSE) {

My site has found this location (and similar locations in other modules), and perhaps it also occurs elsewhere in backup_migrate?

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

uv516 created an issue. See original summary.

danrod’s picture

Assigned: Unassigned » danrod
danrod’s picture

I see it in other files as well:

Deprecated: Drupal\backup_migrate\Core\Plugin\PluginManager::__construct(): Implicitly marking parameter $services as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/backup_migrate/src/Core/Plugin/PluginManager.php on line 39

Deprecated: Drupal\backup_migrate\Core\Plugin\PluginManager::__construct(): Implicitly marking parameter $config as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/backup_migrate/src/Core/Plugin/PluginManager.php on line 39

More:

Deprecated function: Method mysqli::ping() is deprecated since 8.4, because the reconnect feature has been removed in PHP 8.2 and this method is now redundant in Drupal\backup_migrate\Core\Source\MySQLiSource->_getConnection() (line 194 of modules/contrib/backup_migrate/src/Core/Source/MySQLiSource.php).

And the one that you reported:

PHP Deprecated:  Drupal\backup_migrate\Entity\WrapperEntityBase::access(): Implicitly marking parameter $account as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/backup_migrate/src/Entity/WrapperEntityBase.php on line 114

Deprecated: Drupal\backup_migrate\Entity\WrapperEntityBase::access(): Implicitly marking parameter $account as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/backup_migrate/src/Entity/WrapperEntityBase.php on line 114
danrod’s picture

Title: Deprecated nullable in functions » [PHP 8.4] Deprecated nullable in functions

danrod’s picture

I pushed some changes to fix these PHP 8.4 deprecations issues, as for this warning:

Deprecated function: Method mysqli::ping() is deprecated since 8.4, because the reconnect feature has been removed in PHP 8.2 and this method is now redundant in Drupal\backup_migrate\Core\Source\MySQLiSource->_getConnection() (line 194 of modules/contrib/backup_migrate/src/Core/Source/MySQLiSource.php).

I looked at the official PHP documentation but it is not clear to how to replace it:

...
 else {
        $this->connection = new \mysqli(
          $this->confGet('host'),
          $this->confGet('username'),
          $this->confGet('password'),
          $this->confGet('database'),
          $this->confGet('port'),
          $this->confGet('socket')
        );
      }

      // Throw an error on fail.
      if ($this->connection->connect_errno || !$this->connection->ping()) {
        throw new BackupMigrateException("Failed to connect to MySQL server.");
      }
      // Ensure, that the character set is utf8mb4.
      if (!$this->connection->set_charset('utf8mb4')) {
        throw new BackupMigrateException('UTF8 is not supported by the MySQL server.')
...

Maybe using mysqli_ping() is not really needed at all.

I removed the call to !$this->connection->ping() and rely on $this->connection->connect_errno to check if there's an error connecting to the MySQL server, if anyone has a better idea, please let me know, I'll move it to "Needs Review" for now.

danrod’s picture

Status: Active » Needs review
danrod’s picture

Assigned: danrod » Unassigned
samuhe’s picture

Status: Needs review » Reviewed & tested by the community

The changes fix the deprecation warnings.
As for the ping function, it indeed seems to be redundant and just removing it seems fine to me.

danrod’s picture

I think we can move this to "Fixed" and push this change to the 5.1.x branch, I'll do some testing before doing that.

  • ivnish committed 1c87a3ed on 5.1.x authored by danrod
    fix: #3534121 [PHP 8.4] Deprecated nullable in functions
    
    By: uv516
    By:...
ivnish’s picture

Status: Reviewed & tested by the community » Fixed

Thanks! Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

solideogloria’s picture

Thanks! Looking forward to a release containing the fixes.

solideogloria’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.