Zed PHP Snippets
October 1, 2025 · View on GitHub
A comprehensive collection of PHP snippets for Zed editor, designed to accelerate PHP development with intelligent autocomplete and placeholder support.
✨ Features
- Complete PHP Coverage: 100+ snippets covering all essential PHP patterns
- Smart Placeholders: Tab-navigable placeholders for efficient coding
- Modern PHP Support: Includes PHP 8.x features (enums, match expressions, readonly properties, etc.)
- OOP Ready: Complete class, interface, trait, and abstract class snippets
- Database Integration: PDO snippets for secure database operations
- Control Structures: All loops, conditionals, and modern syntax patterns
- Best Practices: Type hints, strict types, and modern PHP conventions
📦 Installation
Via Zed Extensions (Recommended)
- Open Zed editor
- Press
Cmd/Ctrl + Shift + Pto open the command palette - Type "extensions" and select "zed: extensions"
- Search for "PHP Snippets"
- Click "Install"
Manual Installation
-
Clone this repository:
git clone https://github.com/seekode/zed-php-snippets -
Copy the extension to your Zed extensions directory:
- macOS:
~/.config/zed/extensions/ - Linux:
~/.config/zed/extensions/ - Windows:
%APPDATA%\\Zed\\extensions\\
- macOS:
-
Restart Zed
🚀 Usage
Simply start typing any PHP keyword or use the prefix shortcuts. The snippets will appear in the autocomplete menu.
Quick Start Examples
| Prefix | Output | Description |
|---|---|---|
php | <?php \$0 | PHP opening tag |
class | Class structure | Complete class definition |
func | Function structure | Function definition |
if | if ($condition) { } | If statement |
foreach | foreach ($array as $value) { } | Foreach loop |
try | Try-catch block | Exception handling |
📋 Available Snippets
Basics
php- PHP opening tag<?phpphpc- PHP opening and closing tag<?php ?>php=- Echo short tag<?= ?>echo- Echo statementprint- Print statementvar- Variable assignmentdef- Define constantconst- Const declaration
Control Structures
if- If statementife- If-else statementifel- If-elseif-else statementter- Ternary operatornc- Null coalescing operatorswitch- Switch casematch- Match expression (PHP 8+)
Loops
for- For loopforeach- Foreach loop (value only)foreachk- Foreach loop (key-value)while- While loopdo- Do-while loop
Functions
func- Function declarationfuncr- Function with return typefn- Anonymous functionarrow- Arrow function (PHP 7.4+)
Classes & OOP
class- Class declarationconstruct- Constructor with property promotion (PHP 8+)pubm- Public methodprim- Private methodprom- Protected methodsm- Static methodget- Getter methodset- Setter methodinterface- Interface declarationtrait- Trait declarationabstract- Abstract classextends- Class extensionimplements- Interface implementationuse- Use traitenum- Enum declaration (PHP 8.1+)readonly- Readonly property (PHP 8.1+)
Arrays
arr- Array declarationarra- Associative arrayarrp- Array pusharray_map- Array map functionarray_filter- Array filter functionarray_reduce- Array reduce functionin_array- In array checkarray_key_exists- Array key exists checkcount- Count array elements
Exception Handling
try- Try-catch blocktryf- Try-catch-finally blockthrow- Throw exception
Namespaces & Imports
namespace- Namespace declarationuses- Use statementuseas- Use statement with alias
File Inclusion
req- Requirereqo- Require onceinc- Includeinco- Include once
Utility Functions
isset- Isset checkempty- Empty checkdie- Die statementexit- Exit statementvd- Var dumppr- Print rve- Var export
Superglobals
$get- $_GET$post- $_POST$req- $_REQUEST$sess- $_SESSION$cook- $_COOKIE$serv- $_SERVER$file- $_FILES
Variables
global- Global variablestatic- Static variablesession- Session start
JSON
json_encode- JSON encodejson_decode- JSON decode
Database (PDO)
pdo- PDO connectionpdoq- PDO querypdop- PDO prepared statementpdoi- PDO insertpdou- PDO updatepdod- PDO delete
File Operations
fgc- File get contentsfpc- File put contentsfexists- File existsisdir- Is directory
Strings
heredoc- Heredoc syntaxnowdoc- Nowdoc syntaxconcat- String concatenationinterp- String interpolationexplode- Explode string to arrayimplode- Implode array to stringsprintf- Sprintf formattingpreg_match- Regex matchpreg_replace- Regex replacestr_replace- String replacetrim- Trim stringstrtolower- String to lowercasestrtoupper- String to uppercaseucfirst- Uppercase first characterstrlen- String lengthsubstr- Substring
Documentation
/**- PHPDoc comment blockprop- PHPDoc propertystrict- Strict types declaration
🎯 Smart Placeholders
Snippets use numbered placeholders ($1, $2, etc.) that you can tab through:
// Typing 'func' + Tab
function functionName(params)
{
// Tab to function name, type it, Tab to params, type them, Tab to body
}
The $0 placeholder indicates the final cursor position.
🛠️ Customization
You can modify snippets by editing the snippets/php.json file. Each snippet follows this structure:
{
"Snippet Name": {
"prefix": "trigger-text",
"body": [
"line1",
"line2"
]
}
}
💡 Examples
Creating a Class
Type classp + Tab:
class ClassName
{
private type $property;
public function __construct(type $property)
{
$this->property = $property;
}
// cursor ends here
}
Database Query
Type pdop + Tab:
$stmt = $pdo->prepare('SELECT * FROM table WHERE id = :id');
$stmt->execute(['id' => $id]);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
Try-Catch Block
Type try + Tab:
try {
// code
} catch (Exception $e) {
// handle exception
}
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
- Fork the repository
- Clone your fork
- Make your changes
- Test in Zed
- Submit a pull request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Zed Team for creating an amazing editor
- PHP community for best practices and standards
- Community feedback and contributions
📞 Support
- Issues: GitHub Issues
- Zed Community: Zed Discord
- Documentation: Zed Documentation
Happy coding with Zed! 🚀