Home › PHP › Modern PHP Copilot path instructions

Modern PHP Copilot path instructions

Path-specific Copilot instructions for PHP 8.4 code: strict types, typed properties, enums, readonly, and PSR-12.

GitHub CopilotPHP

How to use

Save this as .github/instructions/php.instructions.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

Note: Review and test before use. Provided as is, without warranty. See Terms.

.github/instructions/php.instructions.mdDownload  
---
applyTo: "**/*.php"
description: Modern PHP conventions
---

# PHP 8.4

- Start files with `declare(strict_types=1);` where the project does. Follow PSR-12 / the repo's PHP-CS-Fixer or Pint config.
- Type everything: parameters, return types (including `void`, `never`), and properties. Use union and nullable types instead of docblock-only types; add generics in PHPDoc (`@return list<Order>`) for static analysis.
- Value objects and DTOs as `final readonly class` with constructor property promotion.
- Enums (backed `enum Status: string`) instead of class constants for fixed sets.
- Use `match` over `switch` for value mapping; first-class callables (`strlen(...)`) and named arguments where they help readability.
- Property hooks and asymmetric visibility (`public private(set)`) are available in 8.4; use them only if the codebase already does.
- Exceptions: throw specific exception classes; never suppress errors with `@`.
- Database access through the framework ORM or PDO prepared statements; never interpolate input into SQL.
- Escape output for the context (`htmlspecialchars` or the template engine).
- Composer: add deps with `composer require`; don't edit `composer.lock` by hand.

## Check
PHPStan/Psalm at the configured level and the test suite (PHPUnit or Pest) pass.

More: all PHP rules · all GitHub Copilot rules

Related rules

C# / .NET Copilot path instructions

Path-specific Copilot instructions for C# files on .NET 10: nullable types, async, records, and logging.

GitHub Copilot.NET / ASP.NET Core

ASP.NET Core Copilot instructions

Copilot instructions for ASP.NET Core on .NET 9/10: minimal APIs, EF Core, nullable types, and xUnit tests.

GitHub Copilot.NET / ASP.NET Core

Go Copilot path instructions

Path-specific Copilot instructions (.instructions.md) for Go 1.27 code: errors, context, stdlib routing, and tests.

GitHub CopilotGo

Java + Gradle Copilot path instructions

Path-specific Copilot instructions for Java 25 LTS code built with Gradle: records, null safety, and JUnit 5 tests.

GitHub CopilotJava

Laravel Copilot instructions

GitHub Copilot instructions for Laravel 11+ apps with Eloquent, Pest, and Form Requests.

GitHub CopilotLaravel

Python Copilot path instructions

Path-specific Copilot instructions for Python 3.12+ files: typing, error handling, uv/ruff tooling, and pytest.

GitHub CopilotPython

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.