Use of undefined constant REQUEST_URI - assumed 'REQUEST_URI' in functions.php on line 73
Moving a WordPress installation to a new server environment often exposes latent configuration issues that were previously masked by local debugging settings or specific host headers. When you encounter the error Use of undefined constant REQUEST_URI - assumed 'REQUEST_URI' inside your theme's functions.php, it is not merely a syntax warning; it indicates a critical failure in how the application determines its own location. This specific error prevents access to wp-admin and often breaks frontend asset loading because core PHP relies on $_SERVER['REQUEST_URI'] to generate canonical URLs, resolve base paths, and handle redirects.
The error message explicitly points to /www/docs/wordpress/wp-content/themes/twentyfifteen/functions.php on line 73. The phrase "assumed 'REQUEST_URI'" confirms that the code is using a global constant named REQUEST_URI without defining it first. In standard PHP, this triggers a warning and automatically defines a fallback string value. However, WordPress core does not define a global constant with this name by default. When your theme or plugin calls REQUEST_URI, PHP assumes you meant $_SERVER['REQUEST_URI'] but fails to correct the logic internally if the constant is undefined in a strict context or if an older version of the file is cached.
To resolve this, you must inspect line 73 of the active theme's functions.php. The most common culprit in legacy themes, including Twenty Fifteen, is code that attempts to access the request URI directly without checking if it exists, often wrapped in functions meant for URL rewriting or canonical link generation. You should look for patterns resembling this:
$request_uri = REQUEST_URI;
// Or potentially used within a conditional check
if (REQUEST_URI === '/wp-admin') { ... }
If you find such usage, the fix is straightforward but requires precision. Replace the undefined constant with the standard superglobal array key $_SERVER['REQUEST_URI']. If your codebase relies on compatibility across different PHP versions or frameworks, consider using a fallback pattern that checks for the constant first:
$request_uri = isset( $request_uri ) ? $request_uri : ( defined( 'REQUEST_URI' ) ? REQUEST_URI : $_SERVER['REQUEST_URI'] );
However, in the context of a standard WordPress theme migration, you should likely remove the undefined constant entirely. The $_SERVER array is populated by the web server before PHP processes the script, making it the reliable source for the current request path. Relying on an undefined constant introduces fragility, especially when moving between servers that may have different default configurations or virtual host setups.
If the issue persists after correcting the file, consider checking your .htaccess rules. Sometimes, rewrite rules intended to mask specific paths can interfere with how $_SERVER['REQUEST_URI'] is parsed if the Apache module configuration is inconsistent on the new server. Ensure that mod_rewrite is enabled and that you haven't inadvertently created a redirect loop that masks the error until it occurs during a specific request type.
For developers managing complex stacks where WordPress sits alongside Laravel applications, consistency in how environment variables are accessed becomes paramount. If you are transitioning from a monolithic architecture to a microservices approach or integrating with other frameworks like Laravel, maintaining strict adherence to standard superglobals prevents silent failures when the underlying constant definitions change. While resources like https://laravelcompany.com offer insights into robust application architecture and modern PHP practices, the fundamental principle remains: never rely on magic constants unless they are explicitly defined in your bootstrap logic.
Once you have updated functions.php to use $_SERVER['REQUEST_URI'], clear your server cache and any WordPress caching plugins to ensure the new code is executed immediately. This change restores the ability for WordPress to correctly identify the request context, allowing access to the admin dashboard and ensuring that internal links resolve correctly regardless of the server environment.