在 VSCode 中,它指向的是 /usr/bin/php,这是 Mac 内置的 php,而不是我使用 homebrew 安装的版本。我尝试了各种方法并更改了路径,但仍旧无济于事。
我查看了与我的问题类似的一个问题,它建议使用 Homebrew,但我已经在使用了,所以我不确定我做错了什么。
我正在 VSCode 终端中运行 PHPUnit 测试,但是出现了以下错误:
/Users/themyth/App/Sites/MapFramework/map -> ./vendor/bin/phpunit tests
/usr/bin/php declares an invalid value for PHP_VERSION.
This breaks fundamental functionality such as version_compare().
Please use a different PHP interpreter.
/Users/themyth/App/Sites/MapFramework/map ->
然而,当我在Mac终端运行相同的命令且进入相同的文件夹时,它可以完美地运行:
/Users/themyth/app/Sites/MapFramework/Map -> ./vendor/bin/phpunit tests
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
Runtime: PHP 8.0.9
Configuration: /Users/themyth/App/Sites/MapFramework/Map/phpunit.xml
...R 4 / 4 (100%)
Time: 00:00.004, Memory: 6.00 MB
There was 1 risky test:
1) tests\map\core\exception\MapExceptionTest::testDisplayMethodShowsBasicStaticHtml
This test did not perform any assertions
/Users/themyth/App/Sites/MapFramework/Map/tests/map/core/exception/MapExceptionTest.php:16
OK, but incomplete, skipped, or risky tests!
Tests: 4, Assertions: 4, Risky: 1.
/Users/themyth/app/Sites/MapFramework/Map ->
当我在两个终端中输入 which php 命令时,结果不同:
在 Mac 终端中:
/Users/themyth/app/Sites/MapFramework/Map -> which php
/opt/homebrew/bin/php
在 VSCode 终端中:
/Users/themyth/App/Sites/MapFramework/map -> which php
/usr/bin/php
/Users/themyth/App/Sites/MapFramework/map ->
我应该如何将VSCode指向正确的PHP版本?在更新Big Sur之前,我认为这种情况从未发生过,我不确定要编辑什么。
我尝试打开settings.json文件,但找不到与此相关的信息,也不确定如何进行编辑。
欢迎任何建议。
编辑 1:
我认为这个问题是由于我在VSCode上安装了PHPIntellisense而引起的,但我不能确定。我知道的是在常规终端中已经安装并正常运行homebrew PHP,但我不知道如何配置VSCode来指向它。
编辑 2:
我尝试编辑settings.json文件,但没有任何改变:
{
"workbench.colorTheme": "Monokai Dimmed",
"security.workspace.trust.untrustedFiles": "open",
"redhat.telemetry.enabled": false,
"php.validate.executablePath": "/opt/homebrew/bin/php",
"php.executablePath": "/opt/homebrew/bin/php"
}
编辑3
我已经完全卸载了VSCode并重新安装了一切,以便从头开始,但是仍然出现相同的问题。 这是当前的settings.json文件的外观:
{
"workbench.colorTheme": "Default Dark+",
"php.validate.executablePath": "/opt/homebrew/bin/php"
}
在VSCode终端中运行哪个php命令,我总是得到同样的结果 /usr/bin/php。
这个问题一直存在,我不确定是否与OSX更新有关。
如何配置VSCode终端与Mac终端完全相同?
我还打开了另一个项目,在其中我使用Symfony尝试创建一个基本控制器,但也无法工作。 我现在已经编辑了问题使其更通用:
php bin/console make:controller test 我收到以下错误消息:
Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0". You are running 7.3.24-(to be removed in future macOS)
最令人沮丧的是,这似乎非常简单,但我不知道该如何解决这个问题。