Make WordPress Core

Opened 4 years ago

Closed 3 years ago

#52323 closed defect (bug) (worksforme)

Fatal error: Undefined constant "ABSPATH"

Reported by: mayhem30's profile Mayhem30 Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.6
Component: General Keywords: close reporter-feedback
Focuses: Cc:

Description

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 (6)

#1 @sabernhardt
4 years 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
4 years 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
4 years 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
4 years 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
4 years 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.

#6 @hellofromTonya
3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

I tested with WP 5.6.4 and PHP 8. Could not reproduce the problem. I suspect the follow up problem reported is due to a plugin or theme.

As this ticket is marked for close and the reporter hasn't followed up, closing this ticket as worksforme.

@Mayhem30 if this is still a problem with all plugins deactivated and using a default theme, please reopen this ticket and provide more details including step-by-step of how to reproduce it. This extra information helps contributors to investigate.

Note: See TracTickets for help on using tickets.