Table of Contents

2. Common Patterns AI Uses

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.


1. The "Array First" Instinct

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.


2. Over‑Using Static Methods

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.


3. Mixing Old and New PHP Styles

AI often blends:

Example:

/** @var string $name */
public string $name;

This is syntactically valid but architecturally incoherent.


4. Inventing Patterns From Other Languages

AI frequently imports ideas from:

These patterns “look right” to the model
but don’t exist in PHP.


5. Over‑Engineering Simple Problems

AI sometimes produces:

This is noise, not architecture.

Modern PHP favors clarity over ceremony.


6. Using Modern Features Decoratively

AI loves:

…but often uses them without purpose.

Examples:

Modern features express intent, not decoration.


7. Forgetting About Data Shape

AI often:

Modern PHP is about predictable shape.


8. Missing the Edges of the Language

AI sometimes:

These slips are subtle but important.


Summary

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.