/php:php-oopfrom php
Provides PHP-specific OOP examples for cross-language rules (Tell Don't Ask, collections, whole object, IteratorAggregate, self-describing value objects). Activates when designing PHP classes or discussing encapsulation.
Ships in php. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
The rules are defined in
craft:oop-principles. This skill provides PHP / Symfony examples plus PHP-specific patterns.
// ❌ AVOID — caller queries and decides
foreach ($identityDocument->getRequiredFieldNames() as $fieldName) {
$file = $identityDocument->getFileByFieldName($fieldName);
if ($file !== null) { continue; }
// ... re-download logic
}
// ✅ CORRECT — object exposes behavior
foreach ($identityDocument->getMissingExistingFiles() as $fieldName => $existingFile) {
// Object already determined which files are missing
}
// ❌ AVOID — N separate properties = N identical code paths
final class FormData {
private ?File $frontFile = null;
private ?File $backFile = null;
private ?File $passportFile = null;
}
// ✅ CORRECT — one keyed collection
final class FormData {
/** @param array<string, File> $files */
private array $files = [];
public function addFile(string $fieldName, File $file): void { /* ... */ }
}
// ❌ AVOID — caller destructures
$collection->add(
documentType: $document->type,
documentName: $document->originalFileName,
downloadUrl: $url,
);
// ✅ CORRECT — pass the whole object
$collection->addFromDocument($document, $url);
IteratorAggregatePHP-specific: implement IteratorAggregate to allow foreach while keeping internals private.
/** @implements \IteratorAggregate<string, FileInfo> */
final class FilesCollection implements \IteratorAggregate
{
public function __construct(private array $files = []) {}
public function add(string $name, FileInfo $file): void
{
$this->files[$name] = $file;
}
public function getIterator(): \ArrayIterator
{
return new \ArrayIterator($this->files);
}
}
// Usage: foreach ($collection as $name => $file) { ... }
// ❌ AVOID — consumer needs external fieldName → fileType mapping
final class UploadFile {
public function __construct(
public string $content,
public string $originalFileName,
) {}
}
// ✅ CORRECT — object carries its own type
final readonly class UploadFile {
public function __construct(
public FileTypeEnum $type,
public string $content,
public string $originalFileName,
) {}
}
Readonly placement (per-property vs class-level) is php-8-2's call, not this skill's.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub fabiensalles/claude-marketplace --plugin php10 skills in this plugin
/php-8-0ACTIVATE when calling a constructor, method or function with four or more arguments in a PHP 8.0+ project — value objects, contract requests, factories, projections, test fixtures. Covers: mandatory named arguments from the fourth argument on. DO NOT use for: calls of three arguments or fewer, PHP 8.1 features (see php-8-1), PHP 8.2 features (see php-8-2), PHP 8.3 features (see php-8-3)./php-8-1ACTIVATE when passing a method as a callback in a PHP 8.1+ project — event listeners, validator callbacks, Twig functions, array_map/usort callables. Covers: mandatory first-class callable syntax (`$this` method reference with `(...)`) over array/string callables. DO NOT use for: general PHP syntax, PHP 8.2 features (see php-8-2), PHP 8.3 features (see php-8-3)./php-Other plugins' skills for the same job