Zum Inhalt springen

Early Materialization (ARCH7056)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key php.orm.early-materialization · Severity warning · Category orm

Filtering or sorting in PHP memory after pulling a query into an array moves work that belongs in the database into the application. Unneeded rows are fetched over the wire and memory balloons.

<?php
$users = User::all()->toArray();
$active = array_filter($users, fn($u) => $u['active']); // in-memory filter
<?php
$active = User::where('active', true)->get(); // filter in the DB

Push filtering, ordering, and aggregation into the query’s WHERE/ORDER BY.