折腾:
【未解决】mac中如何在MAMP中调试WordPress的php代码
期间,但是此处想要调试WordPress的插件的php代码:
点击 手动同步 后:

代码:
/Users/crifan/dev/dev_root/crifan.com/mamp/wordpress/wp-content/themes/twentyseventeen/functions.php
1 2 3 | ... $path = $_SERVER[ 'HTTP_HOST' ] . $_SERVER[REQUEST_URI]; ... |
会报错:

1 2 | 出现异常。 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
1 2 | // define( 'WP_DEBUG' , false ); define( 'WP_DEBUG' , true ); |
然后直接就报错了:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | ( ! ) 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
这人自己解决了bug
line 73 in functions.php
1 | $path = $_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'REQUEST_URI' ]; |
把
1 | $path = $_SERVER[‘HTTP_HOST’] . $_SERVER[REQUEST_URI]; |
改为:
1 | $path = $_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'REQUEST_URI' ]; |
去改:
1 2 | // $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
自带代码中有个语法错误:
1 | $path = $_SERVER[ 'HTTP_HOST' ] . $_SERVER[REQUEST_URI]; |
改为:
1 | $path = $_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'REQUEST_URI' ]; |
即可避免此处的报错:
1 | 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