隔了几年,世界上最好的语言又向我招手。
PHP还是那个PHP,phpstorm换成了vs code。
so,先搞个环境。
环境搭建过程:
- 安装windows 11
- 安装wampserver 3.1
- git clone项目代码
- 安装vs code
- 安装vs code插件PHP Intelephense 支持代码跳转;
- 安装vs code php debug插件,支持debug;
- wampserver切换至php7.1,并开启php_xdebug插件。
一、vs code安装插件


二、wampserver开机x_debug插件
zend extensions勾选xdebug。

重启wampserver后,发现wampserver无法启动。
查看php.ini后发现是默认配置文件错误,修改后如下:

重启wampserver成功,查看phpinfo()。

三、打断点Debug
vs code内部debug断点发现并未生效。
百度后,发现vscode和php.ini还需要分别配置,所以继续配置。
3.1 配置php.ini 打开xdebug远程调试
配置后见下图:
[xdebug]
zend_extension ="c:/wamp64/bin/php/php7.1.9/zend_ext/php_xdebug-2.5.5-7.1-vc14-x86_64.dll"
xdebug.remote_handler = "dbgp"
xdebug.remote_enable = true
xdebug.remote_port = 9003
xdebug.remote_host = "127.0.0.1"
xdebug.remote_autostart = true
xdebug.profiler_enable = off
xdebug.profiler_enable_trigger = Off
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir ="c:/wamp64/tmp"
xdebug.show_local_vars=0

3.2 VS code 配置 launch.json
vs打开项目后,点击run and debug菜单。并创建launch.json

修改调试端口如下。(实际上无需修改)

点击debug run图标。

代码打断点并调用API。

调用后可见已经跳入到断点中,可以单步调试。

四、代码跳转
虽然安装了PHP Intelephense,但Ctrl+单击函数后,貌似自己开发的代码可以跳转,但laravel自己的函数无法跳转。
解决方法一:引用Laravel包时,使用全路径。
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;