Notice: Use of undefined constant REQUEST_URI - assumed 'REQUEST_URI' in …functions.php on line 73

wordpress.stackexchange https://wordpress.stackexchange.com/questions/370460

سؤال

When I tried to edit my menu, it appeared

HTTP ERROR 500

Then I set define('WP_DEBUG', true); in wp-config.php

Once I try to save the menu, the following error appears:

Notice: Use of undefined constant REQUEST_URI - assumed 'REQUEST_URI' in /www/web/keenker/public_html/wp-content/themes/keenker/functions.php on line 73

The tricky thing is, my line 73 in functions.php is

return trim($title);

And throughout the functions.php file, I don't even have REQUEST_URI parameters.

Appreciate for any help.

هل كانت مفيدة؟

المحلول

*Without quotes PHP interprets the REQUEST_URI as a constant** but corrects your typo error if there is no such constant and interprets it as string.

When error_reporting includes E_NOTICE, you would probably get an error such as:

Notice: Use of undefined constant REQUEST_URI - assumed 'REQUEST_URI' in <file path> on line <line number>

But if there is a constant with this name, PHP will use the constant’s value instead. (See also Array do's and don'ts)

So always use quotes when you mean a string. Otherwise it can have unwanted side effects.

And for the difference of single and double quoted strings, see the [PHP manual about strings](http://docs.php.net/manual/en/languag

نصائح أخرى

I fixed the issue myself by editing a line in functions.php and it no longer shows the error message for me. The error was:

Warning: Use of undefined constant REQUEST_URI – assumed ‘REQUEST_URI’ (this will throw an Error in a future version of PHP) in /var/www/web33/web/wp-content/themes/slanted-master/functions.php on line 73

So on line 73 in functions.php I changed the line mentioned in the error message to:

$path = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى wordpress.stackexchange
scroll top