php
Language-specific super-code guidelines for php.
PHP: Idiomatic Efficiency Reference
When to Use
- Use this skill when the task matches this description: Language-specific super-code guidelines for php.
Table of Contents
- [Arrays & Collections](#arrays)
- [Type Safety](#types)
- [Error Handling](#errors)
- [String Handling](#strings)
- [OOP & Modern PHP](#oop)
- [Functions & Closures](#functions)
- [Anti-patterns specific to PHP](#antipatterns)
1. Arrays & Collections {#arrays}
// ❌ Manual accumulation
$result = [];
foreach ($items as $item) {
if ($item->isActive()) {
$result[] = strtoupper($item->getName());
}
}
// ✅
$result = array_map(
fn($i) => strtoupper($i->getName()),
array_filter($items, fn($i) => $i->isActive())
);
// ❌ Manual key-value grouping
$grouped = [];
foreach ($items as $item) {
$grouped[$item->getCategory()][] = $item;
}
// ✅ (PHP 8.1+) — or use the loop above; PHP lacks a built-in groupBy
// The foreach is actually idiomatic PHP for grouping. No need to force array_* here.
// ❌ Checking isset then accessing
if (isset($data['key'])) {
$value = $data['key'];
} else {
$value = 'default';
}
// ✅
$value = $data['key'] ?? 'default';
// ❌ array_push for single element
array_push($items, $newItem);
// ✅
$items[] = $newItem;
**Use array_map/array_filter for transforms. The foreach loop is fine w
Subscribers only
The full skill, its 1 bundled files and every download is included with every paid Complete AI plan.
Details
| Source | community |
|---|---|
| License | — |
| Risk label | safe ("critical" means the skill may run commands or touch files — read before use) |
| Files | SKILL.md |
| Added | 2026-06-16 |
