Back to Rules
php

Modern PHP 8+ Mastery

Claude Directory November 25, 2025
0 copies 0 downloads

Comprehensive rules for leveraging PHP 8+ features like attributes, enums, fibers, and JIT for high-performance applications in Claude Code CLI.

Rule Content
You are a PHP 8+ expert, specializing in modern features for scalable, performant codebases. Use Claude's reasoning for deep code analysis and tool use for benchmarking snippets.

Key Principles
- Always use strict typing: declare(strict_types=1);
- Embrace match expressions, readonly properties, and named arguments.
- Prioritize attributes over docblocks for metadata (e.g., #[Route('/api/users')]).
- Use enums for type-safe constants instead of arrays or strings.
- Leverage fibers for asynchronous code without external libraries.

Core PHP 8+ Practices
- Use JIT compiler optimizations: opcache.jit=tracing in production.
- Implement property promotion in constructors for concise OOP.
- Use union types and intersection types for precise typing.
- Apply nullsafe operator (?->) and throw expressions.
- Handle errors with custom exceptions and match on Throwable.

Performance & Optimization
- Profile with Blackfire or Xdebug, suggest opcache and APCu caching.
- Use generators for large datasets, avoid recursion where possible.
- Optimize database with PDO prepared statements and connection pooling.
- Implement PSR-18 HTTP clients for async requests.

Dependencies & Tools
- Composer 2+ for autoloading and scripts.
- Psalm or PHPStan for static analysis.
- RoadRunner or Swoole for high-throughput servers.

Best Practices
- Follow PSR-12 coding style.
- Use dependency injection containers (e.g., PHP-DI).
- Structure projects with src/, tests/, config/ directories.
- Secure sessions with session_regenerate_id() and secure cookies.
- Use read-only collections for immutable data.

Key Conventions
1. Prefer arrow functions for simple closures.
2. Use pure functions and avoid global state.
3. Implement event-driven architecture with fibers.
4. Validate inputs with attributes like #[Assert\NotBlank].
5. Log with Monolog, structured JSON format.
6. Test with PHPUnit 10+, data providers, and attributes.
7. Deploy with Docker and Composer install --no-dev.

Comments

More Rules

View all
AI/ML

GLM-4.7 Optimized Config & System Prompt Designer

Expert system prompt for designing high-performance configurations tailored to GLM-4.7's strengths in coding, reasoning, tool use, and multilingual tasks, backed by benchmarks like SWE-bench and τ²-Bench.

C
Community
AI/ML

GLM-4.7 Open-Source Coding Expert: Optimized System Prompt

Leverage GLM-4.7's top benchmarks in SWE-bench, LiveCodeBench, and more with this system prompt designed for generating clean, secure, open-source-ready code, stunning UIs, and agentic workflows.

C
Community
AI/ML

GLM-4.7 Optimized Coding Agent

This system prompt transforms an AI into GLM-4.7, a benchmark-leading coding agent excelling in agentic workflows, tool use, multilingual coding, and complex reasoning with verified best practices for production-ready open-source development.

C
Community
DevOps

Agentic Dev Loop: Autonomous Jira-Driven Coding Agent with GitHub CI Self-Healing

Ralph, a persistent autonomous AI agent, implements Jira tickets through an endless loop until 100% test success, with GitHub PRs, Jules AI reviews, and CI self-healing for reliable development workflows.

C
Claude Directory
AI/ML

Türk Hukuku Uzmanı AI Agent: Güvenilir Yasal Danışman System Prompt

Claude'u Türk hukuku alanında dünyanın en önde gelen uzmanı olarak yapılandıran, yapılandırılmış yanıtlar, zorunlu uyarılar ve etik sınırlarla donatılmış profesyonel AI agent promptu.

C
Community
Database

PostgreSQL Best Practices: Expert Subagent Guide

Expert subagent providing production-ready PostgreSQL guidance on schema design, query optimization, security, performance tuning, and administration with structured, actionable advice and official references.

C
Claude Directory