我刚刚将 Mac M1 更新到 Big Sur 11.5.2,VSCode 中的某些内容似乎已损坏。 我无法使用已安装的最新 home-brew php。
在 VSCode 中,它指向 /usr/bin/php,这是用 php 构建的 Mac,这不是我在 home-brew 中使用的那个。我尝试了一切并改变了路径,但仍然是同样的事情。
我检查了一个与我类似的问题,它建议的是使用我已经在做的 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 版本?我认为这在进行大苏尔更新之前不会发生,而且我不知道要编辑什么。
我尝试打开settings.json,但找不到任何有关此信息,并且我不知道如何编辑它。
如有任何建议,我们将不胜感激。
我认为这个问题是在我在 VSCode 上安装 PHPIntellisense 后发生的,但不能确定,我所知道的是它之前是有效的。 我不知道如何配置 VSCode 以指向已安装并在常规终端中完美运行的自制 PHP
{
"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"
}
{
"workbench.colorTheme": "Default Dark+",
"php.validate.executablePath": "/opt/homebrew/bin/php"
}
当我在 VSCode 的终端中执行 which php 时,我总是得到相同的结果 /usr/bin/php同样的问题仍然存在,我不确定这是否是因为 OSX 更新。
如何将 VSCode 终端配置为与 Mac 终端完全相同?
我还打开了另一个项目,我正在其中使用 Symfony,并且我正在尝试创建一个基本控制器,但它也不起作用。 我现在已将问题编辑为更通用:
php bin/console make:控制器测试 我收到以下错误:
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)
最令人沮丧的是,这看起来如此简单,我不明白我需要做什么来解决这个问题
nano ~/.zshrc
在文件顶部有:
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
将此行放在下面:
export PATH=/opt/homebrew/opt/[email protected]/bin:$PATH
保存并关闭,重新启动终端即可正常工作。注意:我写的是
[电子邮件受保护],但是您可以对使用自制程序安装的所有版本执行此操作
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 0,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"runtimeExecutable": "/opt/homebrew/bin/php",
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
},
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"runtimeExecutable": "/opt/homebrew/bin/php"
}
]
}