Problem/Motivation

method_exists() did not throw exceptions on unexpected values.

TypeError: method_exists(): Argument #1 ($object_or_class) must be of type object|string, null given in method_exists() (line 123 of /web/modules/contrib/simple_sitemap/src/Plugin/simple_sitemap/UrlGenerator/CustomUrlGenerator.php)

Steps to reproduce

add custom link :/ admin/config/search/simplesitemap/custom
Generate sitemap

Proposed resolution

replace in CustomUrlGenerator.php line 123

'lastmod' =>method_exists($entity, 'getChangedTime') ?
        date('c', $entity->getChangedTime()) : NULL,

by

'lastmod' =>($entity !== NULL && method_exists($entity, 'getChangedTime')) ?
        date('c', $entity->getChangedTime()) : NULL,
CommentFileSizeAuthor
simple_sitemap-php8-error-1.patch806 bytespierrelbz

Comments

pierrelbz created an issue. See original summary.

gbyte’s picture

Category: Bug report » Task

There appears to be a change in PHP 8 where method_exists accepts only an object or string. Drupal is yet to be compatible with PHP 8 so demoting this to task status.

  • gbyte committed 93dd78c on 8.x-3.x
    Issue #3186997 by pierrelbz, gbyte: PHP 8 TypeError: method_exists()
    
gbyte’s picture

Title: method_exists » PHP 8 TypeError: method_exists()
Version: 8.x-3.8 » 8.x-3.x-dev
Status: Active » Fixed

Thanks, pushed to dev.

pierrelbz’s picture

Thanks !

Status: Fixed » Closed (fixed)

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