PHP Language Standards

Enforce modern PHP 8.x standards with strict typing and match expressions.

51|6|Updated Mar 28, 2019
One-click install
npx skills add https://github.com/Mte90/dotfiles --skill php-language-standards
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: PHP Language Standards
Source: https://github.com/Mte90/dotfiles/tree/main/.config/opencode/skills/php/language
Command: npx skills add https://github.com/Mte90/dotfiles --skill php-language-standards

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill enforces modern PHP 8.x language standards and best practices, ensuring code quality, maintainability, and performance.

Core Features & Use Cases

  • Strict Typing: Enforces declare(strict_types=1); for robust type safety.
  • Modern Syntax: Promotes the use of Constructor Property Promotion, readonly properties, and match expressions.
  • Type Hinting: Encourages comprehensive scalar, union, and intersection type hinting.
  • Use Case: Refactor legacy PHP codebases to adopt modern features, improving code clarity and reducing runtime errors.

Quick Start

Apply strict typing and modern PHP 8.x features to the provided PHP code.

Frequently Asked Questions about PHP Language Standards

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce strict typing and modern syntax in PHP 8.x?

To enforce strict typing and modern syntax in PHP 8.x, apply standards requiring `declare(strict_types=1);`, constructor property promotion, `readonly` properties, and `match` expressions. This improves code clarity, maintainability, and reduces runtime errors.

What are the benefits of refactoring legacy PHP to use match expressions and readonly properties?

Refactoring legacy PHP to use `match` expressions and `readonly` properties improves code quality and maintainability. It enforces type safety, replaces legacy switch statements for value mapping, and ensures immutable state where required.

Does this PHP coding standard require comprehensive type hinting for scalar and union types?

Yes, this PHP coding standard requires comprehensive type hinting including scalar, union, and intersection types. This ensures robust type safety and adherence to modern language standards across new development and refactored legacy code.

When do I need to use constructor property promotion in PHP?

You need to use constructor property promotion in PHP when modernizing class definitions to reduce boilerplate. This standard promotes its use alongside strict typing and readonly properties to improve overall code clarity and maintainability.

What is the best way to avoid legacy switch statements in PHP 8.x?

The best way to avoid legacy switch statements in PHP 8.x is to replace them with `match` expressions for value mapping. This enforces modern language standards, reduces runtime errors, and improves code maintainability.