Menu

1 / 2

CLAUDE.md for PHP: 13 Rules That Make AI Write Modern, Secure, Idiomatic PHP

DEV Community·Olivia Craft·6 months ago
#cE79LzMi
#rule#php#claudemd#ai#exit
Reading 0:00
15s threshold

If you're using Claude or another AI assistant for PHP development without a CLAUDE.md , you've seen this pattern: the AI generates working code, but it's PHP 5-era style — no type hints, mysql_* functions, procedural globals, or die() error handling.

PHP has evolved dramatically. PHP 8.x has union types, enums, fibers, named arguments, match expressions, and readonly properties. Modern PHP is a different language from what most AI training data contains. Without explicit rules, AI defaults to the lowest common denominator.

A CLAUDE.md file at your repo root tells the AI which decade you're working in. Here are the 13 rules that have the highest impact.

Rule 1: Enforce strict types on every file

Every PHP file must start with `declare(strict_types=1);` immediately after the opening tag. No exceptions — including scripts, controllers, helpers, and test files.

Enter fullscreen mode

Exit fullscreen mode

Without strict_types , PHP silently coerces values.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.