Modern PHP relies on:
AI often generates code that looks object‑oriented but violates these conventions.
Your mental model helps you see when something is out of place.
A class defines:
class User { public string $name; public function greet(): string { return "Hello, {$this->name}"; } }
Objects created from the class live only for the duration of the request
—
there is no persistent memory unless you build it yourself.
Namespaces give structure:
namespace App\Models; class User { ... }
They prevent:
AI sometimes invents namespaces that don’t exist.
Your mental model helps you catch that instantly.
Modern PHP uses PSR‑4 autoloading, which maps:
Example:
App\Models\User
maps to:
src/Models/User.php
If the structure doesn’t match, autoloading breaks
—
and this is one of the most common AI‑generated errors..
PHP does not load every class at the start.
It loads a class the moment it is first referenced.
This keeps memory usage low and performance predictable
—
a natural fit for PHP’s request‑driven model.
$this
AI often mixes these incorrectly.
Our understanding helps us correct it.
Just like variables and functions:
…all disappear when the request ends.
There is no long‑running application memory unless you build it yourself
(using workers, caches, queues, or external services).
| Modern PHP’s class model is: | - structured - predictable - filesystem‑driven - namespace‑aware - autoloaded on demand |
Once we internalize this,
we can immediately see when AI‑generated code “feels wrong”
— even before we run it.