agentleFS
G1JoshiG1Joshi/Agent-Skills/skills/languages/php/SKILL.md

php

Skill15 starsChanged 42 days agoMITView on GitHub

Expert modern PHP (PHP 8.2/8.3+) assistance covering strict typing, attributes, fibers, Composer, and OPcache. Use when building Laravel/Symfony web apps, developing REST APIs, or optimizing PHP workloads.

11 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

6 rules. 0 are common, 1 is distinctive, and 5 are very specific to this project.

  • 0

    Common

    Most of the 10 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use PHP 8 constructor property promotion with readonly:

    line 98
  2. Very specific:

    Always Add declare(strict_types=1);: Enforce strict scalar type checking at the top of every single PHP file.

    line 122
  3. Distinctive:

    Use PHPStan or Psalm at Level 8+: Integrate static analysis in CI to eliminate type bugs and undefined method calls.

    line 123
  4. Very specific:

    Use DateTimeImmutable: Prevent accidental time-mutation bugs by replacing mutable DateTime with DateTimeImmutable.

    line 125
  5. Very specific:

    Use raw superglobals ($_POST, $_GET): Validate incoming parameters via framework Request classes and validation schemas.

    line 129
  6. Very specific:

    Use weak comparison (==): Always use strict equality (===) to avoid unintended type coercion.

    line 130

“Common” is measured: kept by at least 6 in 10 of the 10 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

PHP

A popular specific-purpose scripting language that is especially suited to web development.

When to Use

  • Modern Full-Stack Web Development: Powering high-velocity Laravel and Symfony web backends with rich ecosystem tooling.
  • Enterprise CMS Platforms: Building and extending WordPress, Drupal, and headless CMS architectures.
  • High-Performance Asynchronous APIs (FrankenPHP / Swoole): Running persistent in-memory PHP workers serving thousands of requests per second.
  • Rapid CRUD & API Engineering: Building robust APIs quickly with PHP 8.3/8.4 typed properties, attributes, and match expressions.

Quick Start

<?php
$name = "World";
echo "Hello, $name!";

$colors = ["red", "green", "blue"];
foreach ($colors as $color) {
    echo $color . "<br>";
}
?>

Core Concepts

Modern Strict Typing & Constructor Promotion (PHP 8.2+)

Enforces strict scalar types, readonly classes, and promoted constructor properties:

<?php
declare(strict_types=1);

namespace App\Domain;

final readonly class Order
{
    public function __construct(
        public string $id,
        public float $amount,
        public OrderStatus $status = OrderStatus::Pending,
        public \DateTimeImmutable $createdAt = new \DateTimeImmutable()
    ) {}
}

enum OrderStatus: string
{
    case Pending = 'PENDING';
    case Paid = 'PAID';
    case Shipped = 'SHIPPED';
}

Expressive match Expressions & First-Class Callables

Replaces verbose switch statements with strict type comparison and returned values:

function getDiscountPercentage(OrderStatus $status): float
{
    return match ($status) {
        OrderStatus::Pending => 0.0,
        OrderStatus::Paid    => 0.05,
        OrderStatus::Shipped => 0.10,
    };
}

Modern Fiber-Based Concurrency & Persistent Runtimes

Runs concurrent fibers and persistent memory workers with FrankenPHP:

$fiber = new Fiber(function (): void {
    $value = Fiber::suspend('paused');
    echo "Resumed with: $value
";
});

$result = $fiber->start();
$fiber->resume('active');

Common Patterns

Constructor Promotion and Readonly Properties

Problem: Verbose boilerplate required to declare, type, and assign class properties.

Solution: Use PHP 8 constructor property promotion with readonly:

<?php
declare(strict_types=1);

readonly class UserProfile
{
    public function __construct(
        public int $id,
        public string $name,
        public string $email,
        public array $roles = ['user']
    ) {}
}

$user = new UserProfile(1, 'Jane', 'jane@example.com');
echo $user->name;

Best Practices

Do:

  • Always Add declare(strict_types=1);: Enforce strict scalar type checking at the top of every single PHP file.
  • Use PHPStan or Psalm at Level 8+: Integrate static analysis in CI to eliminate type bugs and undefined method calls.
  • Deploy with FrankenPHP or Octane: Maximize throughput by serving applications via persistent workers in production.
  • Use DateTimeImmutable: Prevent accidental time-mutation bugs by replacing mutable DateTime with DateTimeImmutable.

Don't:

  • Use raw superglobals ($_POST, $_GET): Validate incoming parameters via framework Request classes and validation schemas.
  • Use weak comparison (==): Always use strict equality (===) to avoid unintended type coercion.
  • Ignore Composer lock files: Always commit composer.lock and run composer install --no-dev --optimize-autoloader in production.

Troubleshooting

ErrorCauseSolution
TypeError: Argument 1 passed must be of the type ...Strict types enabled and caller passed mismatched type.Cast argument explicitly or verify caller inputs.
Fatal error: Allowed memory size of ... bytes exhaustedScript exceeded memory_limit loading large dataset.Use generators (yield) or increase memory_limit in php.ini.
Class '...' not foundAutoloader not included or Composer autoloader stale.Add require __DIR__ . '/vendor/autoload.php'; and run composer dump-autoload.

References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.