Make WordPress Core

Opened 7 weeks ago

Last modified 9 days ago

#52323 new defect (bug)

Fatal error: Undefined constant "ABSPATH"

Reported by: Mayhem30 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.6
Component: General Keywords: close reporter-feedback
Focuses: Cc:


I'm using WordPress 5.6 with PHP 8.01

Fatal error: Undefined constant "ABSPATH" in /wp-includes/functions.php on line 8

Change History (5)

#1 @sabernhardt
7 weeks ago

@Mayhem30 Does your wp-config.php file have this at the very end?

/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
	define( 'ABSPATH', __DIR__ . '/' );

/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';

If you have the older definition, with dirname(__FILE__) instead of __DIR__, does using __DIR__ fix the problem?

#2 @Mayhem30
7 weeks ago

Yes, my file had this at the very end :

if ( !defined('ABSPATH') )
	define('ABSPATH', dirname(__FILE__) . '/');

I've now changed it to :

if ( ! defined( 'ABSPATH' ) ) {
	define( 'ABSPATH', __DIR__ . '/' );

So far, it appears to have solved the issue.

#3 @sabernhardt
7 weeks ago

  • Keywords close added

A change was already made to the sample config file in changeset 47198, but I'll leave this open in case this needs documentation somewhere.

#4 @Mayhem30
9 days ago

I've received this error again, so the issue is somewhere else as well.

PHP Fatal error:  Uncaught Error: Undefined constant "ABSPATH" in /www/example.com/httpdocs/wp-includes/functions.php:8\nStack trace:\n#0 {main}\n  thrown in /www/example.com/httpdocs/wp-includes/functions.php on line 8

I'm using WP 5.6.2 and PHP 8.0.2

#5 @SergeyBiryukov
9 days ago

  • Keywords reporter-feedback added

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

Steps to reproduce the issue on a clean install would be helpful here. Does it still happen with all plugins disabled and a default theme (Twenty Twenty-One) activated?

ABSPATH is first defined in wp-load.php and then in wp-config.php as a fallback. wp-includes/functions.php is loaded far beyond that point, so I don't really see how this could happen in regular usage.

If the issue only happens sporadically and not consistently, it's possible that the site was hacked and some files were replaced.

Note: See TracTickets for help on using tickets.