FortiumPartners avatar

developing-with-php

Modern PHP 8.x development with type system, attributes, enums, error handling, and Composer. Use wh

提供方 FortiumPartners|开源

PHP Skill

Core PHP language patterns, PSR standards, and foundational concepts for modern PHP development.

Purpose

This skill provides PHP language fundamentals applicable to any PHP project—Laravel, Symfony, WordPress, or vanilla PHP. Framework-specific patterns are covered in dedicated skills (see Laravel skill).

When to Load

  • Any PHP backend development
  • Working with Composer packages
  • PSR-compliant library development
  • Understanding core language features before framework abstractions
  • Non-Laravel PHP projects (Symfony, Slim, WordPress)

Key Topics

TopicDescription
PHP 8.x FeaturesEnums, attributes, readonly, match, named args
OOP PatternsTraits, interfaces, design patterns, DI
Handler/Service PatternRepository-like business logic layers
Map/DTO PatternData transformation objects
PDODatabase access, prepared statements, transactions
ComposerAutoloading, PSR-4, scripts
PSR StandardsPSR-4, PSR-12, PSR-7, PSR-11, PSR-15
PHPUnitTesting fundamentals (framework-agnostic)
SecurityInput validation, password hashing, SQL injection prevention

File Structure

php/
├── README.md           # This file
├── SKILL.md            # Quick reference (~800 lines)
├── REFERENCE.md        # Comprehensive guide (~1400 lines)
├── VALIDATION.md       # Coverage matrix
├── templates/
│   ├── composer.template.json
│   ├── phpunit.template.xml
│   ├── class.template.php
│   ├── interface.template.php
│   ├── trait.template.php
│   ├── enum.template.php
│   ├── handler.template.php
│   ├── map_data.template.php
│   └── pdo_repository.template.php
└── examples/
    ├── php8_features.example.php
    ├── pdo_crud.example.php
    ├── design_patterns.example.php
    └── handler_architecture.example.php

Relationship to Other Skills

SkillRelationship
LaravelBuilds on this skill; Laravel skill assumes PHP fundamentals
PrismaAlternative ORM approach (TypeScript)
PythonComparable language skill structure

Context7 Integration

Use Context7 for:

  • PHP RFC details and edge cases
  • Specific extension documentation (e.g., sodium, ffi)
  • Framework-specific PHP usage (covered in framework skills)

Quick Start

<?php
// PHP 8.3 features
enum Status: string {
    case Active = 'active';
    case Inactive = 'inactive';
}

readonly class UserDTO {
    public function __construct(
        public string $name,
        public string $email,
        public Status $status = Status::Active,
    ) {}
}

// Handler pattern
class UserHandler {
    public function __construct(
        private readonly PDO $db
    ) {}

    public function create(UserDTO $data): int {
        $stmt = $this->db->prepare(
            'INSERT INTO users (name, email, status) VALUES (?, ?, ?)'
        );
        $stmt->execute([$data->name, $data->email, $data->status->value]);
        return (int) $this->db->lastInsertId();
    }
}

Version

  • Skill Version: 1.0.0
  • PHP Version: 8.1+ (8.3 recommended)
  • Last Updated: 2025-01-01
developing-with-php - 适用于 Claude Code 与 Cursor 的 AI 智能体 Skill | Agent Skills