Early previewThis guide is in development. Items tagged verify are still being checked against official docs.
nebx Learn
GitHub
Menu
Home/PHP/Best practices
PHP

PHP

Pragmatic server-side language that powers a large share of the web.

Paradigm
OOP, procedural, functional features
Typing
Dynamic with gradual typing (strict_types)
Memory
Reference counting + cycle collector
Runs
Zend Engine, bytecode + OPcache, optional JIT
Concurrency
Shared-nothing per request; Fibers (8.1)

Best practices

Habits experienced PHP teams agree on.

declare(strict_types=1) in every file

Type errors surface instead of being coerced.

Follow PSR standards

PSR-4 autoloading, PSR-12 / PER coding style, PSR-7/15 HTTP messages and middleware.

Static analysis in CI

PHPStan or Psalm at a high level catch bugs that tests miss.

Prepared statements only

Use PDO or your ORM's parameter binding for every query.

Enable OPcache in production

Caches compiled bytecode so scripts are not re-parsed on every request.

Saved in this browser only. Part of Clean code foundations (0/5).