最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】VSCode调试WordPress的PHP代码报错:Warning Use of undefined constant REQUEST_URI

WordPress crifan 1474浏览 0评论
折腾:
【未解决】mac中如何在MAMP中调试WordPress的php代码
期间,但是此处想要调试WordPress的插件的php代码:
点击 手动同步 后:
代码:
/Users/crifan/dev/dev_root/crifan.com/mamp/wordpress/wp-content/themes/twentyseventeen/functions.php
...
    $path = $_SERVER['HTTP_HOST'] . $_SERVER[REQUEST_URI];
...
会报错:
出现异常。
Warning: Use of undefined constant REQUEST_URI - assumed 'REQUEST_URI' (this will throw an Error in a future version of PHP)
需要去搞清楚,如何才能继续正常的调试WordPress的插件的php代码
去看调用堆栈
找到建议DEBUG=True
先去设置看看是否有变化
/Users/crifan/dev/dev_root/crifan.com/mamp/wordpress/wp-config.php
// define('WP_DEBUG', false);
define('WP_DEBUG', true);
然后直接就报错了:
( ! ) Warning: Use of undefined constant REQUEST_URI - assumed 'REQUEST_URI' (this will throw an Error in a future version of PHP) in /Users/crifan/dev/dev_root/crifan.com/mamp/wordpress/wp-content/themes/twentyseventeen/functions.php on line 73
Call Stack
#
Time
Memory
Function
Location
1 
0.0147 
440488 
{main}( ) 
.../index.php:0 
2 
0.0182 
488136 
require_once( '/Users/crifan/dev/dev_root/crifan.com/mamp/wordpress/wp-admin/admin.php' ) 
.../index.php:10 
3 
0.0198 
500744 
require_once( '/Users/crifan/dev/dev_root/crifan.com/mamp/wordpress/wp-load.php' ) 
.../admin.php:31 
4 
0.0202 
512688 
require_once( '/Users/crifan/dev/dev_root/crifan.com/mamp/wordpress/wp-config.php' ) 
.../wp-load.php:37 
5 
0.0219 
592048 
require_once( '/Users/crifan/dev/dev_root/crifan.com/mamp/wordpress/wp-settings.php' ) 
.../wp-config.php:97 
6 
0.8850 
25236440 
include( '/Users/crifan/dev/dev_root/crifan.com/mamp/wordpress/wp-content/themes/twentyseventeen/functions.php' ) 
.../wp-settings.php:426 
去搜索:
WordPress functions.php Warning Use of undefined constant REQUEST_URI
Warning: Use of undefined constant REQUEST_URI – assumed ‘REQUEST_URI’ | WordPress.org
https://wordpress.org/support/topic/warning-use-of-undefined-constant-request_uri-assumed-request_uri/
这人自己解决了bug
line 73 in functions.php
$path = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
wordpress – Use of undefined constant REQUEST_URI – assumed ‘REQUEST_URI’ in functions.php on line 73 – Stack Overflow
$path = $_SERVER[‘HTTP_HOST’] . $_SERVER[REQUEST_URI];
改为:
$path = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
去改:
// $path = $_SERVER['HTTP_HOST'] . $_SERVER[REQUEST_URI];
$path = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
注意到:
此处路径是:
/Users/crifan/dev/dev_root/crifan.com/mamp/wordpress/wp-content/themes/twentyseventeen/functions.php
是WordPress官网的自带的主题twentyseventeen的代码
竟然是语法错误。。。
然后再去调试,看看问题是否彻底消失了。
错误真的消失了。
【总结】
WordPress的主题twentyseventeen中的functions.php
wordpress/wp-content/themes/twentyseventeen/functions.php
自带代码中有个语法错误:
$path = $_SERVER['HTTP_HOST'] . $_SERVER[REQUEST_URI];
改为:
$path = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
即可避免此处的报错:
Warning: Use of undefined constant REQUEST_URI - assumed 'REQUEST_URI' (this will throw an Error in a future version of PHP) in /Users/crifan/dev/dev_root/crifan.com/mamp/wordpress/wp-content/themes/twentyseventeen/functions.php on line 73
了。

转载请注明:在路上 » 【已解决】VSCode调试WordPress的PHP代码报错:Warning Use of undefined constant REQUEST_URI

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
90 queries in 0.187 seconds, using 22.08MB memory