All skills
asyrafhussin avatar

/php-best-practices

@e7ea05d

PHP 8.x modern patterns, PSR standards, and SOLID principles. Use when reviewing PHP code, checking type safety, auditing code quality, or ensuring PHP best practices. Triggers on "review PHP", "check PHP code", "audit PHP", or "PHP best practices".

Use this Skill: https://skilld.dev/gh/asyrafhussin/agent-skills/php-best-practices

This session only. Nothing lands on disk.

rulestype-property-types.md

≈497 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Property Type Declarations

Always declare types for class properties (PHP 7.4+).

Bad Example

<?php

declare(strict_types=1);

class Product
{
    // No property types - state can be anything
    private $id;
    private $name;
    private $price;
    private $categories;
    private $createdAt;

    public function __construct($id, $name, $price)
    {
        $this->id = $id;           // Could be int, string, null...
        $this->name = $name;       // Could be anything
        $this->price = $price;     // Hope it's numeric
        $this->categories = [];
    }
}

Good Example

<?php

declare(strict_types=1);

class Product
{
    private int $id;
    private string $name;
    private float $price;
    private array $categories = [];
    private ?string $description = null;
    private DateTimeImmutable $createdAt;
    private ?DateTimeImmutable $updatedAt = null;

    public function __construct(
        int $id,
        string $name,
        float $price,
        ?DateTimeImmutable $createdAt = null
    ) {
        $this->id = $id;
        $this->name = $name;
        $this->price = $price;
        $this->createdAt = $createdAt ?? new DateTimeImmutable();
    }

    public function getId(): int
    {
        return $this->id;
    }

    public function getName(): string
    {
        return $this->name;
    }
}

Why

  • State Integrity: Properties always contain expected types
  • Null Safety: Nullable types make null handling explicit
  • Initialization Enforcement: Uninitialized typed properties throw errors
  • Documentation: Property types serve as inline documentation
  • IDE Support: Enables better autocompletion and refactoring
  • Static Analysis: Tools can verify property usage throughout codebase

Source: SKILL.md on GitHub

No alerts17d5 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    This skill is a comprehensive and safe resource for PHP 8.x best practices. It provides structured guidance on type safety, modern PHP syntax, PSR standards, and secure coding practices (such as prepared statements and password hashing). The agent is instructed to use standard environment detection commands (php -v, grep) to tailor its advice. No malicious patterns or security risks were identified.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

  • Runlayer6mo

    39 files scanned · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at e7ea05d. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 7 months ago
Other metadata
metadata
{
  "author": "php-community",
  "version": "2.1.0",
  "phpVersion": "8.0 - 8.5"
}

README badge

README badge for asyrafhussin/agent-skills/php-best-practices