Make WordPress Core

#59113 closed defect (bug) (invalid)

Call to undefined function str_contains() in wp-includes/load.php:1618

Reported by: lernerconsult's profile lernerconsult Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.3
Component: Bootstrap/Load Keywords: reporter-feedback close
Focuses: Cc:

Description

WordPress 6.3 site with PHP 7.4

PHP Fatal error: Uncaught Error: Call to undefined function str_contains() in wp-includes/load.php:1618
It seems to be because of using str_contains, a PHP 8.0 function, on a PHP 7.4 site

https://core.trac.wordpress.org/browser/trunk/src/wp-includes/compat.php#L423 defines str_contains for pre-PHP8 sites.

"If" that PHP8 function is called before the "if ( ! function_exists( 'str_contains' ) ) { " statement is executed, the function is undefined.

https://www.php.net/manual/en/functions.user-defined.php "Functions need not be defined before they are referenced, except when a function is conditionally defined".

Change History (5)

#1 follow-up: @SergeyBiryukov
16 months ago

  • Keywords reporter-feedback added

Hi there, welcome to WordPress Trac! Thanks for the report.

The line number in the error message points to the wp_convert_hr_to_bytes() function. In all the scenarios I can think of, by the time this function runs, the polyfills from compat.php should already be loaded.

  1. Could you provide the steps to reproduce the issue on a clean install?
  2. Could you confirm that your wp-settings.php file has compat.php on line 34?

#2 in reply to: ↑ 1 ; follow-up: @emmaedeh
16 months ago

Thanks for the response @SergeyBiryukov

I am currently having this same issue, as I try to recover a backup of my WordPress site.
I have added "require ABSPATH . WPINC . '/compat.php';" in line 34 as you advised and it fixed that. But now I have this new error -> (Fatal error: Cannot redeclare _wp_can_use_pcre_u() (previously declared in /home/healqils/splitsecondsermons.com/wp-includes/compat.php:28) in /home/healqils/splitsecondsermons.com/wp-includes/compat.php on line 28)

Any Help?

Replying to SergeyBiryukov:

Hi there, welcome to WordPress Trac! Thanks for the report.

The line number in the error message points to the wp_convert_hr_to_bytes() function. In all the scenarios I can think of, by the time this function runs, the polyfills from compat.php should already be loaded.

  1. Could you provide the steps to reproduce the issue on a clean install?
  2. Could you confirm that your wp-settings.php file has compat.php on line 34?

#3 in reply to: ↑ 2 ; follow-up: @SergeyBiryukov
16 months ago

Replying to emmaedeh:

But now I have this new error -> (Fatal error: Cannot redeclare _wp_can_use_pcre_u() (previously declared in /home/healqils/splitsecondsermons.com/wp-includes/compat.php:28) in /home/healqils/splitsecondsermons.com/wp-includes/compat.php on line 28)

I'm sorry to hear you are having issues with your website. It looks like the error is caused by an incomplete upgrade.

It appears that the wp-settings.php file was not updated during the upgrade to 6.3, and the compat.php file is now loaded twice. It should be removed from line 107 where it was previously included.

Please note that there were other changes to the wp-settings.php file in 6.3 as well, so I would recommend downloading the latest version of WordPress and replacing the file with a fresh copy, that should fix the issue.

#4 in reply to: ↑ 3 @emmaedeh
15 months ago

Thanks @SergeyBiryukov This was helpful.
It fixed the issue.

#5 @ironprogrammer
12 months ago

  • Keywords close added
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

As this ticket has been open with unresolved reporter-feedback for over 3 months, I'm closing it for now.

Please feel free to reopen if the details requested in comment:1 can be addressed. Thanks!

Note: See TracTickets for help on using tickets.