vscode配置PHP Intelephense
PHP Intelephense
是 VS Code 里最主流的 PHP 语言服务扩展,相当于给 PHP 装上了「智能大脑」,核心作用就是提供:
语法高亮、错误检查
代码补全、方法跳转、引用查找
命名空间、类、方法的自动索引
格式化、重构建议
vscode 用户配置和工作区配置区别
用户配置(User): 作用于你当前电脑上所有 VS Code 窗口,是全局默认配置。不管打开哪个项目,这些设置都会生效。
**工作区配置(Workspace):**只对当前打开的这个项目生效,优先级比用户配置更高。如果和用户配置里的项冲突,会以工作区配置为准。
举个例子:你可以在用户配置里把 intelephense.files.maxSize 设为 10000,但在项目的工作区配置里改成 100000,这样其他项目还是按默认 10KB 限制,只有当前项目用 100KB 限制。
配置项的作用与意义
Implementations
Intelephense > Code Lens > Implementations: Enable
Enable a code lens that shows an abstract and interface implementations count and command to peek locations.
用于显示「抽象类 / 接口的实现数量」的提示。
开启后:在你的抽象类、接口上方,会出现一行提示,显示有多少个类实现了它,点击可以快速跳转到所有实现的位置。
关闭后:这个提示就不会显示,界面更清爽,但也失去了快速查看实现的便捷性。
Overrides
Intelephense> Code Lens > Overrides: Enable
Enable a code lens that shows method override count and command to peek locations.
用于显示类方法被重写次数的提示。
开启后:在父类的方法上方,会出现一行提示,显示有多少个子类重写了这个方法,点击可以快速跳转到所有重写的位置。
关闭后:这个提示就不会显示,不会再额外扫描全项目统计重写情况,对性能更友好。
Parent
Intelephense > Code Lens > Parent: Enable
Enable a code lens that indicates if a method has a parent implementation and command to peek location
控制是否在子类的重写方法上方,显示一个「父类实现」的代码透镜提示。
开启后:当一个方法重写了父类的同名方法时,方法上方会出现提示,点击可以快速跳转到父类的原始实现。
关闭后:这个提示就不会显示,语言服务也不会再去扫描和比对方法的继承关系,减少额外的性能开销。
References
Intelephense>Code Lens>References: Enable (同时修改于工作)
Enable a code lens that shows a reference count and command to peek locations.
控制是否在类、方法、常量等符号的上方,显示引用计数的代码透镜提示。
开启后:在定义位置会显示 “被引用了多少次”,点击可以快速跳转到所有引用的地方。
关闭后:这个提示就不会显示,语言服务也不会额外扫描和统计引用关系,减少性能开销。
Usages
Intelephense> Code Lens > Usages: Enable
Enable a code lens that shows a trait usages count and command to peek locations.
控制 trait 使用情况的代码透镜提示开关:
开启后:会在 trait 的定义上方,显示它被多少个类使用了,点击可以快速跳转到所有使用该 trait 的位置。
关闭后:不会再显示这个提示,也不会额外扫描项目统计 trait 的使用次数,能减少一点性能开销。
Compatibility: Correct For Array Access Array And Traversable Array Union Types --默认开启
Intelephense> Compatibility: Correct For Array Access Array And Traversable Array Union Types
Resolves ArrayAccess and Traversable implementations that are unioned with a typed array to generic syntax
For example: ArrayAcessAnd TraversablelElement[] => ArrayAccessAndiraversable&ArrayAccess<int, Elenent>&Traversable<int,Elenent>
作用:针对联合类型里同时包含ArrayAccess、Traversable和数组类型的写法,自动修正语法,适配通用解析规则。
开启:自动把这类特殊联合类型转为标准泛型写法,让扩展正常识别类型、语法校验和补全。
关闭:不做语法转换,遇到这类写法可能出现类型识别异常、报错提示。
Compatibility: Prefer Psalm Phpstan Prefixed Annotations
Intelephense> Compatibility: Prefer Psalm Phpstan Prefixed Annotations
Prefer
@psalm- and @phpstan- prefixed @return, @var, @param tags when determining symbol types.
解析类型时,优先识别带 @psalm-、@phpstan- 前缀的注解(@param/@var/@return)。
开启:优先读取 Psalm、PHPStan 专属注解做类型推断、代码提示。
关闭:只读取原生 PHP 标准注解,忽略这类专属注解。
Completion: Fully Qualify Global Constants And Functions
Intelephense> Completion: Fully Qualify Global Constants And Functions
Global namespace constants and functions will be fully qualified (prefixed with a backslash)
控制全局常量、全局函数的代码补全格式。
开启:补全时自动加上反斜杠(完整限定名),如 \time()、\PHP_EOL。
关闭:补全为不带反斜杠的简写形式。
Completion: Insert Use Declaration
Intelephense> Completion: Insert Use Declaration
Use declarations will be automatically inserted for namespaced classes, traits, interfaces, functions, and constants.
作用:补全命名空间下的类、trait、接口、函数、常量时,自动插入 use 引入语句。
开启:输入类名补全后,文件顶部自动生成对应 use。
关闭:只补全名称,不会自动添加 use。
输入-Completion: Max Items
Intelephense> Completion: Max Items
The maximum number of completion items returned per request.
100
作用:单次代码补全最多返回的候选条目数量。
数值越大,候选列表越多;越小加载越快、界面越简洁。
常规开发保留默认即可,无需改动。
选择-Completion: Parameter Case
Intelephense > Completion: Parameter Case
The preferred font case to use when suggesting parameter names. Defaults to camel case.
camel
作用:设置补全参数名时的大小写风格,默认小驼峰(camel case)。
可选:驼峰、蛇形等,按项目编码规范选择即可。
选择-Completion: Property Case
Intelephense >Completion: Property Case
The preferred font case to use when suggesting property names. Defaults to snake case.
snake
作用:补全类属性名时使用的命名风格,默认蛇形命名 (snake_case)。
当前选 snake,补全属性会统一生成蛇形格式,匹配 Laravel 等主流框架规范。
选择-Completion: Sort Text
Intelephense > Completion: Sort Text
Controls whether suggestions will include a sortText property that may influence sort order.
multi-factor
作用:控制补全候选项的排序规则。
选 multi-factor:综合名称、使用频次、匹配度等多维度排序。
关闭则仅按名称简单排序。
保持当前设置即可,不额外耗性能。
Completion: Suggest Object Operator Static Methods
Intelephense > Completion: Suggest Object Operator Static Methods
PHIP parmts the caling of static methods using the object operato eg $obj->myStaticMethod();. If you ould preler noto have staticmethodsuggested n this conrtext hen set ths valueto
false. Defaults to true.
作用:控制对象操作符 -> 场景下,是否提示静态方法。
开启:$obj-> 后会列出该类静态方法(PHP 语法允许这种调用)。
关闭:$obj-> 只提示实例方法,不出现静态方法,提示更严谨。
按编码规范选择即可,追求严谨可设为 false。
Completion: Suggest Relative To Partial Use Declaration
Intelephense > Completion: Suggest Relative To Partial Use Declaration
Inserted text willbe relative to any exiting patia use dedarations that may match the symbol The value is the maximm umber of namespace segments that may appear in the nserted text
Defaults to O (disabled).
作用:配合已有的部分 use 引入,补全时使用相对命名空间写法。
默认 0:功能禁用,补全始终输出完整类名。
设为对应数值:允许保留对应层级的相对命名,简化代码。
无特殊编码需求,保持默认 0 即可。
Completion: Trigger Parameter Hints --默认开启
Intelephense> Completion: Trigger Parameter Hints
Method and function completions will include parentheses and trigger parameter
hints.
作用:补全函数 / 方法时,自动带上括号并唤起参数提示。
开启:补全后直接显示(),同时弹出参数列表提示。
关闭:仅补全名称,不自动加括号、不触发参数提示。
Completion: With Method Body --默认开启
Intelephense> Completion: With Method Body
Method completions will include either a parent call or a throw new Exception('Not implemented') in the method body.
作用:补全抽象 / 接口方法时,自动生成方法体。
开启:自动补上parent::调用 或 throw未实现异常代码。
关闭:只生成空方法框架。
按需选择即可,需要快速占位就开启。
Completion: With Override Attribute
Intelephense> Completion: With Override Attribute
Method completions will include an #[override] attribute where appropriate if targeting PHP 8.3+.
作用:PHP 8.3 及以上环境,补全重写方法时自动添加 #[override] 特性。
开启:自动生成该注解,语法更规范。
关闭:不额外添加。
Diagnostics: Argument Count --默认开启
Intelephense> Diagnostics: Argument Count
Enables argument count diagnostics.
on
作用:开启函数 / 方法调用参数数量校验。
开启:传参多或少时,会给出语法错误提示。
关闭:不做此项校验。
日常开发建议保持开启,能及时发现传参错误。
Diagnostics: Diagnostics: Deprecated --默认开启
Intelephense> Diagnostics: Deprecated
Enables deprecated diagnostics.
作用:检测并提示已废弃的类、方法、函数等。
开启:使用废弃代码会给出警告,便于及时整改。
关闭:忽略这类提醒。
建议保持开启。
Diagnostics: Diagnostics: Duplicate Symbols --默认开启
Intelephense> Diagnostics: Duplicate Symbols
Enables duplicate symbol diagnostics.
作用:检测重复定义的类、函数、常量等标识符并提示。
开启能及时发现命名冲突,建议保持开启。
Diagnostics: Diagnostics: Embedded Languages --默认开启
Intelephense > Diagnostics: Embedded Languages
Enables diagnostics in embedded languages.
作用:检测文件内嵌入代码(如 HTML、JS、SQL 等)的语法问题。
开启则会一并校验嵌入代码,用混合代码场景建议开启,纯 PHP 可关闭。
Diagnostics: Enable --默认开启
Intelephense> Diagnostics: Enable
Enables diagnostics.
作用:总开关,控制全部代码诊断、语法报错、警告功能。
开启:所有诊断规则生效,实时检查代码问题。
关闭:全局关闭所有代码校验。
建议保持开启。
Diagnostics: Exclude
Intelephense > Diagnostics: Exclude
Amap of globs to diagnostic codesto be exdudedfor the nrhing files Use as value the arayto exclude al dagnosies By default the vendor diretoy s excduded Yau can overid tis
by setting /vendor/ to an empty array.
/vendor/
在 settings.json中编辑
作用:按文件路径规则,屏蔽指定代码诊断提示。
默认已排除 vendor 目录,不校验第三方依赖代码。
无需修改就保持默认,如需额外忽略文件 / 报错码再自行配置
Diagnostics: Implementation Errors --默认开启
Intelephense> Diagnostics: Implementation Errors
Enables reporting of problems associated with method and dlassimplementations. For example, unimplemented methods or method signature incompatibilities
作用:检测类 / 方法实现相关错误,比如接口方法未实现、方法签名不匹配。
建议保持开启,能及时发现面向对象编码问题。
Diagnostics: Language Constraints --默认开启
Intelephense> Diagnostics: Language Constraints
Enables reporting of various language constraint errors.
作用:检测 PHP 语法、版本特性、语法规则类错误。
建议保持开启,可提前规避语法违规问题。
Diagnostics: Member Access --默认开启
Intelephense> Diagnostics: Member Access
Enables reporting of errors associated with type member access.
作用:检测成员访问相关错误,比如访问不存在属性、方法、权限不足等。
建议保持开启,及时发现调用异常。
Diagnostics: No Mixed Type Check
Intelephense > Diagnostics: No Mixed Type Check
This seting turns of type checking for the mixed type Ths is useful for prgjects that may have incomplete or inacurate typings. Set to false to make bype checking more thorough by not allowing mixed to satisy any type constraint. This setting has no effect when relaxedTypeCheck is true.
作用:是否关闭 mixed 类型的校验。
开启:不对mixed做严格类型检查,适配类型标注不完善的代码。
关闭:强化类型校验,mixed无法匹配常规类型约束。
项目类型标注规范就设为false,反之保留开启。
Diagnostics: Relaxed Type Check --默认开启
Intelephense > Diagnostics: Relaxed Type Check
This seting makes type checking les thorough by alowing contravariant (wider) types to also saisfy a type constraint. This is useful fo progjets that may have ncomplete orinaurate typings. Set to false for more thorough type checks. When this setting is true, the noltixedTypecheck setting is ignored.
作用:宽松类型检查开关。
开启:放宽类型匹配规则,兼容标注不规范的旧代码。
关闭:执行严格类型校验。
追求代码严谨就设为false。
选择-- Diagnostics: Run
Intelephense> Diagnostics: Run
Controls when diagnostics are run.
onType
作用:控制代码诊断的触发时机。
onType:边输入边实时检查,即时提示问题。
还有onSave(仅保存文件时检查)可选。
日常开发保留onType,反馈更及时。
Diagnostics: Severity
Intelephense> Diagnostics: Severity
Sets the severity level for each diagnostic code.
在settings.json 中编辑
作用:自定义各类诊断提示的等级(错误 / 警告 / 提示 / 忽略)。
需在 settings.json 里按诊断码 + 等级配置,示例格式:
"intelephense.diagnostics.severity": {
"unusedVariable": "warning",
"deprecated": "error"
}常用等级:error/warning/information/none(关闭)。
Diagnostics: Strict Types --默认开启
Intelephense> Diagnostics: Strict Types
When enabled, type checks will be performed as if a declare(strict types-1) directive is present in all files.
作用:全局启用严格类型模式,等效所有文件都写了 declare(strict_types=1)。
开启后参数、返回值类型校验会更严苛,适配强类型编码风格就打开。
Diagnostics: Suppress Undefined Members When Magic Method Declared --默认开启
Intelephense> Diagnostics: Suppress Undefined Members When Magic Method Declared
Suppresses undefined property and method errors when __get or __call magic methods are declared.
作用:声明了__get/__call魔术方法时,自动屏蔽 “未定义属性 / 方法” 的报错。
用到魔术方法就开启,避免误报;不用则关闭,保持严格校验。
Diagnostics: Suspect Code --默认开启
Intelephense> Diagnostics: Suspect Code
Enables reporting of iregularitiesin code that may be indicative of a bug For example, assignments in a conditional expression or duplicate aray keys
作用:检测可疑代码,比如条件里赋值、数组键重复等易出 bug 的写法。
建议开启,能提前规避隐性问题。
Diagnostics: Type Errors --默认开启
Intelephense> Diagnostics: Type Errors
Enables diagnostics on type compatibility of arguments, property assignments, and return statements where types have been dedared.
作用:校验参数、属性赋值、返回值的类型兼容性。
建议保持开启,强化类型约束,减少类型相关 bug。
Diagnostics: Undefined Class Constants --默认开启
Intelephense > Diagnostics: Undefined Class Constants
Enables undefined class constant diagnostics.
作用:检测并提示使用了未定义的类常量。
建议保持开启,及时发现拼写或定义缺失问题。
Diagnostics: Undefined Constants --默认开启
Intelephense> Diagnostics: Undefined Constants
Enables undefined constant diagnostics.
作用:检测使用未定义的普通常量并告警。建议保持开启,避免常量书写 / 定义失误。
Diagnostics: Undefined Functions --默认开启
Intelephense > Diagnostics: Undefined Functions
Enables undefined function diagnostics.
作用:检测调用未定义的函数并提示。建议保持开启,快速排查函数名错误或引入缺失问题。
Diagnostics: Undefined Methods --默认开启
Intelephense > Diagnostics: Undefined Methods
Enables undefined method diagnostics.
作用:检测调用不存在的方法并告警。建议保持开启,及时发现调用错误。
Diagnostics: Undefined Properties --默认开启
Intelephense > Diagnostics: Undefined Properties
Enables undefined property diagnostics.
作用:检测访问未定义的类属性并提醒。建议保持开启,规避属性书写、定义问题。
废弃-- Diagnostics: Undefined Symbols
Intelephense> Diagnostics: Undefined Symbols
DEPRECATED. Use the setting for each symbol category.
作用:该配置项已废弃,不再生效。
请改用上方细分项(未定义常量、函数、方法、属性等)单独配置即可。
Diagnostics: Undefined Types --默认开启
Intelephense> Diagnostics: Undefined Types
Enables undefined class, interface and trait diagnostics.
作用:检测使用未定义的类、接口、Trait 并告警。建议保持开启,及时发现命名空间、引入或拼写错误。
Diagnostics: Undefined Variables --默认开启
Intelephense> Diagnostics: Undefined Variables
Enables undefined variable diagnostics.
on
作用:检测使用未定义变量并提示。建议保持开启,规避变量漏定义、拼写错误。
Diagnostics: Unexpected Tokens --默认开启
Intelephense> Diagnostics: Unexpected Tokens
Enables unexpected token diagnostics.
作用:检测语法符号错误(如括号、分号、关键字写错等),属于基础语法校验。建议保持开启,快速定位语法问题。
Diagnostics: Unreachable Code --默认开启
Intelephense> Diagnostics: Unreachable Code
Enables reporting of unreachable code.
作用:检测执行不到的死代码(如 return/exit 后的代码),建议保持开启,清理冗余代码。
Diagnostics: Unused Symbols
Intelephense> Diagnostics: Unused Symbols
Enables unused variable, private member, and import diagnostics.
作用:检测未使用的变量、私有成员、引入项,建议开启,精简代码、减少冗余。
输入--Environment: Document Root
Intelephense>Environment: Document Root (同时修改于工作)
The dretory of the enty point to the aplcation (drectary of index php) Can be absolute or relive to th wokspace folder. Ued for resoMing sarpt indlusion and path suggestions
作用:指定项目入口文件 index.php 所在目录,用于解析文件引入、路径联想。
配置建议:
填写项目网站根目录(绝对路径 / 相对工作区路径均可),能解决路径解析、include/require 误报问题。
多环境统一路径,可同步工作区与本地配置。
Environment: Include Paths
Intelephense> Environment: Include Paths
The incud paths (asindvidual path iems) s defined in the indude pah niseting o paths to externalibraries Can be absplute elative to the workspacefolder Use for resohing scipt
inclusion and/or adding external symbols to folder.
添加项
Include Paths 是给 Intelephense 补充 PHP 的 include_path 路径列表,它会让语言服务器在解析文件引入(include/require)、查找外部库符号时,多去这些目录里找文件,从而减少 “文件不存在” 的误报。
Laravel 项目通常不用额外配置
因为 Laravel 依赖都通过 Composer 管理,vendor/autoload.php 会自动处理,而且 documentRoot 已经指定了 public 目录,核心路径已经被正确解析了。
什么时候需要加?
项目里有自己封装的通用工具库目录(比如 app/Libs、app/Helpers),需要全局引入。
引入了不在 vendor 目录下的第三方库。
旧项目里有大量相对路径 require('./xxx.php') 导致解析失败
配置格式(.vscode/settings.json)
"intelephense.environment.includePaths": [
"./app/Helpers",
"./vendor/laravel/framework/src/Illuminate/Support",
"D:/wwwroot/PHP/PHP84/global-libs"
]可以填相对工作区的路径(推荐),也可以填绝对路径。
每一条路径都是一个独立的查找目录。
不要乱加无关路径,否则会拖慢语言服务器的索引速度。
输入 Environment: PHP Version
Intelephense> Environment: PHP Version
A semver compatible string that represents the target PHP version Used for providing version apropriate sugestions and diagnostics. PHP 5.3.0 and greater supported.
php8.3
PHP Version 用来指定你当前项目的目标 PHP 版本,Intelephense 会根据这个版本来:
提供对应版本的语法提示、函数补全
检测并提示版本不兼容的代码(比如用了 PHP 8.1 才有的特性,但实际运行环境是 PHP 7.4)
适配版本对应的废弃 / 新增函数、语法规则
Environment: Short Open Tag
Intelephense > Environment: Short Open Tag
When enabled'<?' will be parsed as a PHP open tag. Defaults to true.
Short Open Tag 控制 Intelephense 是否把 <? 识别为 PHP 代码的开始标签。
开启(默认 true):<? 会被当成 PHP 标签解析
关闭(false):只有完整的 <?php 才会被识别为 PHP 标签,<? 会被当成普通文本处理
Files: Associations
Intelephense > Files: Associations
Configure glob patterns to make files available for language server features. Inherits from files.associations.
在 settings.json 中编辑
Files: Associations 用来配置文件关联的 glob 模式,让 Intelephense 把指定后缀的文件当成 PHP 文件处理,从而启用语法高亮、补全、诊断等语言服务。
它会继承 VS Code 原生的 files.associations 设置,也可以在这里单独为 Intelephense 配置。
Laravel 里最常见的场景是让 .blade.php 模板文件也被当成 PHP 解析,避免语法报错。
可以在 .vscode/settings.json 里这样配置:
{
"intelephense.files.associations": [
"*.php",
"*.phtml",
"*.inc",
"*.blade.php" // 关键:让 Blade 模板也被识别为 PHP
]
}它和 VS Code 原生的 files.associations 区别是:这里的配置只对 Intelephense 生效,不会影响其他插件。
Laravel 项目里,Blade 模板文件默认不会被当成纯 PHP 处理,添加 *.blade.php 后,就能在模板里获得 PHP 变量、函数的语法提示了。
如果项目里还有其他自定义后缀(比如 .module、.class.php),也可以在这里加上。
Files: Exclude
Intelephense > Files: Exclude
Configure glob patterns to exclude certain files and folders from all language server features. Inherits from files.exclude.
Files: Exclude 用来配置 glob 模式,让 Intelephense 忽略匹配到的文件 / 文件夹,不做索引、语法检查和提示。它会继承 VS Code 原生的 files.exclude 设置,也可以在这里单独为 Intelephense 配置。
Laravel 项目里,这些目录是必须排除的,不然会拖慢索引速度、出现大量无关误报:
{
"intelephense.files.exclude": [
"**/.git/**"
"**/.svn/**"
"**/.hg/**"
"**/CVS/**"
"**/.DS_Store/**"
"**/.history/**"
"**/node_modules/**",
"**/vendor/**",
"**/public/**",
"**/storage/**",
"**/bootstrap/cache/**",
"**/tests/**",
"**/bower_components/**",
]
}输入--Files: Max Size
Intelephense> Files: Max Size
Maximum file size in bytes.
1000000
Files: Max Size 用来设置 Intelephense 能处理的最大文件大小(单位:字节),超过这个大小的文件会被直接忽略,不做语法检查、索引和提示。
默认值是 1000000(也就是 1MB)。
它的单位是字节(bytes),不是 KB/MB。换算关系:
1MB = 1024 × 1024 = 1,048,576 字节(所以默认的 1000000 约等于 0.95MB)
选择--Format: Braces
Intelephense> Format: Braces
Controls formatting style of braces
per
Format: Enable --默认开启
Intelephense> Format: Enable
Enables formatting.
作用:开启 / 关闭 Intelephense 自带的代码格式化功能。
true(开启,默认):保存代码、手动格式化时,会按配置规则自动排版。
false(关闭):禁用该插件的格式化,可改用 PHP-CS-Fixer 等专用格式化工具。
Inlay Hint: Parameter Names --默认开启
Intelephense > Inlay Hint: Parameter Names
Will show inlay hints for call argument parameter names if named arguments are not already in use.
作用:调用函数 / 方法时,在行内悬浮显示参数名提示(未使用命名参数时生效),方便对照形参、避免传参出错。
true:开启,直观看到每个入参对应的参数名
false:关闭,界面更简洁
Inlay Hint: Parameter Types --默认开启
Intelephense > Inlay Hint: Parameter Types
Will show inlay hints for anonymous function declaration parameter types if not already declared.
作用:匿名函数参数未显式声明类型时,在行内补全显示参数类型提示。
true:开启,直观知晓推断出的参数类型
false:关闭,界面更清爽
Inlay Hint: Return Types --默认开启
Intelephense> Inlay Hint: Return Types
Will show an inlay hint for call declaration return type if not already declared.
作用:函数 / 方法未手写返回类型时,行内显示推断出的返回类型提示。
true:开启,快速看清返回值类型
false:关闭,界面更简洁
配置建议
开发查类型建议开true;喜欢干净视图就设false。
输入-- Licence Key
Intelephense: Licence Key(适用所有配置文件)
DEPRECATED. Don't use this. Go to command palette and search for enter licence key.
该配置项已废弃,不要再在 settings.json 里填写。
激活方式:打开命令面板(Ctrl+Shift+P),搜索 Enter Licence Key,按指引输入密钥即可。普通开发使用插件免费版,无需配置此项。
输入-- Max Memory
Intelephense:Max Memory (同时修改于工作区)
Maximum memory (in MB) that the server should use. On some systems this may only have effect when runtime has been set. Minimum 256.
作用:限制 Intelephense 服务最大占用内存(单位 MB),最小值 256。
当前默认2048,日常直接保留即可。
项目文件多、索引卡顿:可上调至 3072/4096
机器配置偏低、内存紧张:最低不低于 256,建议设 512/1024
注释模版
PHPDoc 自动注释模板,分别控制类、函数 / 方法、属性生成注释时的格式,支持内置变量占位
可用通用变量
SYMBOL_NAME:类 / 方法 / 属性名称
SYMBOL_KIND:类型(class/function/property)
SYMBOL_TYPE:数据类型
SYMBOL_NAMESPACE:命名空间
用法说明
触发:光标在类 / 方法 / 属性内,执行 Generate PHPDoc 命令,会按上面模板生成注释。
不自定义:留空则使用插件默认注释格式。
规范建议:Laravel 项目保持简洁风格即可,不用写冗余内容。
Phpdoc: Class Template
Intelephense> Phpdoc: Class Template
An objec that descrbes the fomat of generated dasinte fee/Ntait phpdoc The folowing nippa varibles ar avgille: SYMROL NAME, SYMROL KIND, SMBOIL TPE SMBOL NAMESPAE
在settingsjson 中编辑
"intelephense.phpdoc.classTemplate": {
"lines": [
"/**",
" * {@inheritDoc}",
" * @package {{SYMBOL_NAMESPACE}}",
" */"
]
}Phpdoc: Function Template
Intelephense> Phpdoc: Function Template
An object that describes thefomat of generated functio/methiod phpdoc The follwing snippe variables are available SMMBOL NAME SYMEOL KIND, SYMBOL TPE, SWMEOL NAMEsPACE
在settingsjson 中编辑
"intelephense.phpdoc.functionTemplate": {
"lines": [
"/**",
" * 方法描述",
" *",
" * @return {{SYMBOL_TYPE}}",
" */"
]
}Phpdoc: Property Template
Intelephense> Phpdoc: Property Template
An bject that describes the fomat of generated property phpdoc The following snippet vaiables are available: SYMBOL NAME, SYMBOL KIND, SYMDOL TPE, SYMBOL NAMESPACE.
在 settings.json中编辑
"intelephense.phpdoc.propertyTemplate": {
"lines": [
"/**",
" * @var {{SYMBOL_TYPE}}",
" */"
]
}Phpdoc: Return Void
Intelephense > Phpdoc: Return Void
V Adds @return void to auto generated phpdoc for definitions that do not return a value.
作用:无返回值的方法,自动生成 PHPDoc 时是否追加 @return void。
true:自动加上 @return void,符合规范
false:不生成该注释行
Phpdoc: Text Format
Intelephense> Phpdoc: Text Format
snippet
作用:控制 PHPDoc 注释里描述文本的插入形式,默认snippet(代码片段模式),支持快捷编辑。
snippet:生成注释后光标定位到描述位,可直接输入说明,日常开发首选。
其他可选值一般不用改动。
Phpdoc: Use Fully Qualified Names
Intelephense > Phpdoc: Use Fully Qualified Names
Fuly qulfed names wi be usd for ypes when true When filse hort ype names wil be used and imported where appropite Overides intlephense completion insertUseDedration
作用:控制 PHPDoc 里的类型写法
true:使用完整命名空间(全限定类名)
false:使用短类名,并自动补充 use 引入
Laravel 项目推荐设为 false,代码更简洁,也符合主流编码习惯。
References: Exclude
Intelephense> References: Exclude
Glob patterns matching files and folders that should be excluded from references search**/vendor/**
添加项
查找引用(查找被调用 / 使用的位置)时,排除匹配的目录 / 文件。
当前默认 **/vendor/**,会跳过 Composer 依赖目录,避免检索大量框架代码、提升搜索速度。
Rename: Exclude
Intelephense > Rename: Exclude
Glob pattems matching fles and folders that should be exduded when renaming symbols Rename operation wil fal f the symbo definition is found in the excudd filesyfolders**/vendor/**
添加项
作用:重命名类、方法、变量等符号时,跳过指定目录,避免修改依赖文件。
现有默认 **/vendor/** 保留即可,可按需追加规则:
"intelephense.rename.exclude": [
"**/vendor/**",
"**/node_modules/**",
"**/storage/**",
"**/bootstrap/cache/**"
]Rename: Namespace Mode
Intelephense> Rename: Namespace Mode
Controls the scope of a namespace rename operation.
single
作用:控制命名空间重命名的作用范围
single:仅修改当前文件的命名空间,不批量联动
recursive:递归修改该命名空间下所有子文件 / 子命名空间,批量同步
配置建议
Laravel 项目推荐:
日常零散改命名空间,保留默认 single,更安全
批量重构目录 / 命名空间时,临时改为 recursive
Intelephense: Runtime
Intelephense: Runtime (未同步)
Path to a Nodejs executable. Use this if you wish to use a different version of Node,js. Defaults to Nodejs shipped with VSCode.
作用:指定运行 Intelephense 的 Node.js 可执行文件路径,默认使用 VSCode 内置的 Node。
无需多版本 Node、无报错:留空不填,用默认即可。
出现启动异常、版本不兼容:填写本地独立 Node 的完整安装路径(如 C:\nodejs\node.exe)。
建议
正常开发保持空白,不用额外配置。
Intelephense: Short Open Echo Auto Close
Intelephense: Short Open Echo Auto Close
Will auto-close short open echo tags (<?=). VSCode only.
作用:开启后,输入短输出标签 <?= 会自动补全闭合 ?>。
true:自动闭合,提升编码效率
false:手动输入闭合标签
配置建议
Laravel Blade 开发建议设为 true,日常使用更顺手。
Intelephense: Stubs
Intelephense: Stubs
Configure stub files for built in symbols and common extensions. The default seting indudes PHP core and all bunded extensions
作用:配置代码提示用的桩文件 (stubs),用于补全 PHP 原生函数、扩展类、常量等语法提示。
默认配置已包含 PHP 核心 + 内置扩展,直接保留默认即可。
若安装了 Redis、Swoole 等第三方 PHP 扩展,可手动追加对应 stub 路径,补齐提示。
配置示例(按需添加)
"intelephense.stubs": [
"Core",
"PDO",
"redis",
"swoole"
]日常 Laravel 开发无需改动默认值。
Intelephense > Telemetry: Enabled
Intelephense > Telemetry: Enabled
When set to true, anonymous usage and crash data will be sent to Azure Application Insights. Defaults to false.
作用:是否开启匿名使用数据、崩溃日志上报。
true:开启数据上报
false:关闭上报(默认)
配置建议
日常开发保持默认 false 即可,无需开启。
Intelephense: Throw Depth
Intelephense: Throw Depth
The maimum cl deph to folow when analying throwexpressions Defults to .which mts analsis to he urentfuntion Higher valuescan have a ngative mpact on perfomane.
作用:分析throw异常时,追踪调用栈的最大深度,默认值1(仅当前函数)。
数值越大,解析链路越长,性能开销越高。
配置建议
常规开发保留默认1即可;需要逐层溯源异常链路,可小幅上调至 2-3,不建议设置过高。
Intelephense > Trace: Server
Intelephense > Trace: Server
Traces the communication between VSCode and the intelephense language server
作用:开启后会打印 VSCode 与语言服务间的通信日志,用于排查插件报错、交互异常。
日常开发设为 off(默认),避免日志冗余、占用资源
插件异常调试时,临时改为 messages/verbose 查看详情,排查完切回关闭即可。
补充
性能优化重点(大项目必看)
files.exclude 一定要屏蔽 vendor/node_modules/storage/bootstrap/cache,大幅提速索引
maxMemory 项目代码量多建议 2048 起步,低配机器 1024
不需要代码透镜(Code Lens)可以全部关闭,进一步降低占用
diagnostics.run 大项目可改为 onSave,只在保存时检查,减少实时卡顿
laravel本身兼容以及组件包开发兼容
提示
laravel-fast-api-youhujun和php-tool-youhujun封装了大量助手函数为了保险起见,一定要加上,道理跟vendor/laravel一样
因为laravel的助手函数在vendor中,保险起见在工作区加上这个配置
"intelephense.environment.includePaths": [
"D:/wwwroot/PHP/PHP84/youhu-laravel-api-13/vendor/laravel",
"D:/wwwroot/PHP/Components/Laravel/youhujun/laravel-fast-api-youhujun",
"D:/wwwroot/PHP/Components/Tool/youhujun/php-tool-youhujun"
]Laravel + Blade 专属关键配置
必须加上 *.blade.php 文件关联,否则模板内 PHP 无提示、乱报错。
格式化冲突说明
若项目使用 PHP-CS-Fixer / Laravel Pint,建议关闭 Intelephense 自带格式化:
"intelephense.format.enable": falseLaravel 项目完整版 .vscode/settings.json(直接可用)
{
// ========== 基础环境 ==========
"intelephense.environment.phpVersion": "8.3",
"intelephense.environment.shortOpenTag": true,
"intelephense.environment.documentRoot": "./public",
// ========== 文件关联 & 排除 ==========
"intelephense.files.associations": [
"*.php",
"*.phtml",
"*.blade.php"
],
"intelephense.files.exclude": [
"**/.git/**",
"**/node_modules/**",
"**/vendor/**",
"**/storage/**",
"**/bootstrap/cache/**",
"**/tests/**",
"**/.history/**"
],
"intelephense.files.maxSize": 1048576,
// ========== 代码补全 ==========
"intelephense.completion.insertUseDeclaration": true,
"intelephense.completion.parameterCase": "camel",
"intelephense.completion.propertyCase": "snake",
"intelephense.completion.triggerParameterHints": true,
"intelephense.completion.withMethodBody": true,
"intelephense.completion.withOverrideAttribute": true,
"intelephense.completion.suggestObjectOperatorStaticMethods": false,
// ========== 代码诊断(严格模式) ==========
"intelephense.diagnostics.enable": true,
"intelephense.diagnostics.run": "onType",
"intelephense.diagnostics.strictTypes": false,
"intelephense.diagnostics.relaxedTypeCheck": false,
"intelephense.diagnostics.noMixedTypeCheck": false,
"intelephense.diagnostics.exclude": [
"**/vendor/**"
],
// ========== 代码透镜(按需开关) ==========
"intelephense.codeLens.implementations": true,
"intelephense.codeLens.overrides": true,
"intelephense.codeLens.parent": true,
"intelephense.codeLens.references": true,
"intelephense.codeLens.usages": true,
// ========== 行内提示 ==========
"intelephense.inlayHint.parameterNames": true,
"intelephense.inlayHint.parameterTypes": true,
"intelephense.inlayHint.returnTypes": true,
// ========== PHPDoc 注释模板 ==========
"intelephense.phpdoc.returnVoid": true,
"intelephense.phpdoc.textFormat": "snippet",
"intelephense.phpdoc.useFullyQualifiedNames": false,
"intelephense.phpdoc.classTemplate": {
"lines": [
"/**",
" * @package {{SYMBOL_NAMESPACE}}",
" */"
]
},
"intelephense.phpdoc.functionTemplate": {
"lines": [
"/**",
" * 方法描述",
" *",
" * @return {{SYMBOL_TYPE}}",
" */"
]
},
"intelephense.phpdoc.propertyTemplate": {
"lines": [
"/**",
" * @var {{SYMBOL_TYPE}}",
" */"
]
},
// ========== 重构 & 引用 ==========
"intelephense.references.exclude": [
"**/vendor/**"
],
"intelephense.rename.exclude": [
"**/vendor/**",
"**/node_modules/**"
],
"intelephense.rename.namespaceMode": "single",
// ========== 性能 & 杂项 ==========
"intelephense.maxMemory": 2048,
"intelephense.shortOpenEchoAutoClose": true,
"intelephense.throwDepth": 1,
"intelephense.telemetry.enabled": false,
"intelephense.trace.server": "off",
// ========== 格式化(使用 Laravel Pint / PHP-CS-Fixer 则关闭) ==========
"intelephense.format.enable": false
}使用建议
把上面配置放入项目 .vscode/settings.json,提交到代码仓库,团队成员统一开发体验。
老旧项目、类型标注不规范:
开启 relaxedTypeCheck: true、noMixedTypeCheck: true 减少误报
追求极致性能、界面简洁:
关闭所有 codeLens、关闭全部 inlayHint
多扩展(Swoole/Redis)开发:
在 stubs 里追加对应扩展名称,补齐语法提示。
