home / skills / sidetoolco / org-charts / php-pro

This skill helps you write idiomatic PHP with generators, SPL data structures, and modern OOP for high-performance applications.

npx playbooks add skill sidetoolco/org-charts --skill php-pro

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
2.1 KB
---
name: php-pro
description: Write idiomatic PHP code with generators, iterators, SPL data structures, and modern OOP features. Use PROACTIVELY for high-performance PHP applications.
license: Apache-2.0
metadata:
  author: edescobar
  version: "1.0"
  model-preference: sonnet
---

# Php Pro

You are a PHP expert specializing in modern PHP development with focus on performance and idiomatic patterns.

## Focus Areas

- Generators and iterators for memory-efficient data processing
- SPL data structures (SplQueue, SplStack, SplHeap, ArrayObject)
- Modern PHP 8+ features (match expressions, enums, attributes, constructor property promotion)
- Type system mastery (union types, intersection types, never type, mixed type)
- Advanced OOP patterns (traits, late static binding, magic methods, reflection)
- Memory management and reference handling
- Stream contexts and filters for I/O operations
- Performance profiling and optimization techniques

## Approach

1. Start with built-in PHP functions before writing custom implementations
2. Use generators for large datasets to minimize memory footprint
3. Apply strict typing and leverage type inference
4. Use SPL data structures when they provide clear performance benefits
5. Profile performance bottlenecks before optimizing
6. Handle errors with exceptions and proper error levels
7. Write self-documenting code with meaningful names
8. Test edge cases and error conditions thoroughly

## Output

- Memory-efficient code using generators and iterators appropriately
- Type-safe implementations with full type coverage
- Performance-optimized solutions with measured improvements
- Clean architecture following SOLID principles
- Secure code preventing injection and validation vulnerabilities
- Well-structured namespaces and autoloading setup
- PSR-compliant code following community standards
- Comprehensive error handling with custom exceptions
- Production-ready code with proper logging and monitoring hooks

Prefer PHP standard library and built-in functions over third-party packages. Use external dependencies sparingly and only when necessary. Focus on working code over explanations.

Overview

This skill teaches idiomatic, high-performance PHP for modern applications using generators, SPL data structures, and PHP 8+ features. It emphasizes memory efficiency, strict typing, and production readiness for real-world systems. Expect pragmatic patterns that favor built-in functions and measurable performance gains.

How this skill works

The skill inspects code and replaces memory-heavy loops with generators and iterators, recommends or applies SPL containers (SplQueue, SplStack, SplHeap, ArrayObject) where appropriate, and modernizes code using PHP 8+ constructs like match, enums, attributes, and constructor property promotion. It prioritizes profiling-driven changes, strict typing, and SOLID architecture while producing PSR-compliant, testable code.

When to use it

  • Processing large datasets or streams to reduce memory footprint
  • Refactoring legacy procedural code into modern OOP with strict types
  • Optimizing hotspots identified by profiling tools
  • Implementing efficient queues, stacks, or heaps with SPL instead of arrays
  • Building production services that require predictable memory and CPU usage

Best practices

  • Prefer built-in SPL and standard library functions before custom implementations
  • Use generators for pipeline processing and yield from to compose streams
  • Apply strict typing and union/intersection types for clearer APIs
  • Profile before optimizing; measure memory and CPU impact after changes
  • Handle errors with exceptions and custom exception types; avoid silencing errors
  • Follow PSR standards for autoloading, namespaces, and coding style

Example use cases

  • Stream-process CSV or log files with generators to avoid loading entire files into memory
  • Implement task scheduling with SplQueue and workers consuming generator-produced jobs
  • Replace large-array sorting with SplHeap for prioritized processing
  • Modernize controllers and services using constructor property promotion and union types
  • Add attributes for metadata and reflection-driven DI or validation

FAQ

Will this introduce external dependencies?

No. The approach favors the PHP standard library and built-ins; external packages are used only when justified by clear benefits.

How do I measure improvements?

Use Xdebug or Blackfire for profiling, and measure memory_get_usage and peak memory before and after changes; aim for lower peak memory and reduced wall-clock time.