PHP Rename Symbol (Free)
Free PHP Rename Symbol (F2) support for Visual Studio Code. No premium license required.
Uses AST parsing via php-parser to find and rename PHP symbols across your entire workspace.
Features
- F2 Rename for PHP symbols — works out of the box
- Renames local variables (
$customer) within their scope
- Renames class names across all files (use statements, type hints,
new, extends, implements)
- Renames methods across all files (declarations and calls via
-> and ::)
- Renames properties across all files (declarations and
-> accesses)
- Renames functions across all files (declarations and calls)
- Detects Laravel route patterns like
[Controller::class, 'method']
Usage
- Place your cursor on any PHP symbol
- Press F2
- Type the new name
- Press Enter
All references across your workspace are updated.
Supported Symbols
| Symbol |
Example |
Scope |
| Variable |
$customer |
Current function/method |
| Class |
Customer |
All PHP files |
| Interface |
CustomerInterface |
All PHP files |
| Trait |
HasRoles |
All PHP files |
| Method |
register() |
All PHP files |
| Property |
$this->auth |
All PHP files |
| Function |
helper() |
All PHP files |
Laravel Support
The extension recognizes the [Controller::class, 'method'] pattern commonly used in Laravel route definitions, event listeners, and job dispatching. Renaming a method will also update these string references.
// This 'show' will be renamed too
Route::get('stores/{store}', [CatalogController::class, 'show']);
Requirements
- Visual Studio Code 1.80+
- PHP files in your workspace
No PHP runtime is required for the rename functionality itself.
How It Works
The extension parses PHP files into an Abstract Syntax Tree (AST) using glayzzle/php-parser. When you trigger a rename:
- The file under cursor is parsed to identify the symbol type and name
- For local variables, only the current scope is searched
- For classes, methods, and properties, all
*.php files in the workspace are scanned (excluding vendor/ and node_modules/)
- A
WorkspaceEdit is returned with all the text replacements
Known Limitations
- Renames are name-based, not type-aware. If two unrelated classes have a method with the same name, both will be renamed. Review the changes before confirming.
- Dynamic method calls (
$obj->$method()) are not detected.
- String references outside of the
[Class::class, 'method'] pattern are not detected.
- Very large workspaces (10,000+ PHP files) may experience a short delay during rename.
Support Us
If this extension saved you time, consider supporting development:
| Currency |
Address |
| TRX |
TY4wx4Pd5ftsmRLjZwRq8ikdNenoyXXWsx |
| ETH |
0x872B453BbE046662990e7048d6dC992d09c16e7b |
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
License
MIT