How AI tends to write PHP
— the habits, defaults, shortcuts, and biases that show up again and again.
AI writes PHP with confidence, but it often relies on familiar patterns rather than the deeper shape of the language. These patterns are not “wrong”, but they reveal how AI thinks
— and where it drifts from modern PHP’s architectural intent.
Understanding these patterns helps us guide AI gently back into clarity.
AI defaults to arrays for almost everything:
Example drift:
return [ 'name' => $name, 'email' => $email, 'roles' => ['admin', 'editor'] ];
Modern PHP prefers shape:
Arrays are flexible, but they hide intent.
AI loves static methods
because they’re easy to call and easy to reason about:
UserFactory::create($data);
But static methods:
Modern PHP leans toward → objects with clear lifecycles.
AI often blends:
Example:
/** @var string $name */ public string $name;
This is syntactically valid but architecturally incoherent.
AI frequently imports ideas from:
These patterns “look right” to the model
but don’t exist in PHP.
AI sometimes produces:
This is noise, not architecture.
Modern PHP favors clarity over ceremony.
AI loves:
…but often uses them without purpose.
Examples:
Modern features express intent, not decoration.
AI often:
Modern PHP is about predictable shape.
AI sometimes:
These slips are subtle but important.
AI tends to:
These patterns are not failures
— they are signals.
Once we recognize them, we can guide AI back into the shape of modern PHP with clarity and confidence.
This page describes common behaviors observed in AI models when generating PHP code.
These patterns are not guarantees, but they are consistent enough to be useful when reviewing or guiding AI output.