PHP Project

Language: PHP October 1, 2025

Instruction file for PHP projects with modern features and frameworks.

---
applyTo: "**/*.php"
---

# PHP Development Instructions (2025)

_Last updated: October 2025_

- Always use the fetch tool to look up the latest PHP documentation: https://www.php.net/docs.php
- Use PHP 8.3 or later for new projects
- Leverage modern PHP features: attributes, enums, union types, named arguments
- Follow PSR standards (PSR-1, PSR-2, PSR-4, PSR-12) for coding style
- Use Composer for dependency management
- Implement proper error handling and type declarations

**Core Principles:**

- Use strict types: declare(strict_types=1) at the top of files
- Implement type hints for function parameters and return types
- Use enums for fixed sets of values (PHP 8.1+)
- Leverage attributes for metadata (PHP 8.0+)
- Use null-safe operator ?-> to prevent null errors
- Follow PSR-4 autoloading standard

**Laravel (Recommended Framework):**

- Use Laravel 11+ for modern web applications
- Implement Eloquent ORM for database operations
- Use migrations for database schema management
- Implement proper validation with Form Requests
- Use dependency injection via service container
- Leverage Laravel's built-in features (queues, events, jobs)

**Modern Features:**

- Use constructor property promotion (PHP 8.0+)
- Implement readonly properties (PHP 8.1+)
- Use match expressions instead of switch when appropriate
- Leverage union types for flexible parameters
- Use named arguments for clarity

**Database:**

- Use PDO or Eloquent ORM for database access
- Implement prepared statements to prevent SQL injection
- Use migrations for version-controlled database changes
- Implement proper indexing for performance

**Security:**

- Validate and sanitize all user input
- Use password_hash() and password_verify() for passwords
- Implement CSRF protection
- Use prepared statements for SQL queries
- Set proper session security settings

**Testing:**

- Use PHPUnit for unit testing
- Implement feature tests in Laravel
- Use Pest for modern testing syntax
- Write tests with proper assertions

**Performance:**

- Use OPcache for bytecode caching
- Implement Redis or Memcached for application caching
- Use lazy loading and eager loading appropriately
- Profile with Xdebug or Blackfire

**Summary:**

> For all PHP work, always use the fetch tool to look up the latest documentation from https://www.php.net/docs.php. Write modern, secure, and performant PHP applications.

PHP Backend Programming Language Laravel