php version guide

PHP 7.2 Changes

PHP 7.2 added the object parameter type, bundled the Sodium cryptography extension, added Argon2 password hashing support where available, and started warning about several loose legacy behaviours.

Changes Worth Recognising

  • Use the object type when any object is valid and a narrower interface is not appropriate.
  • Prefer password_hash() and password_verify() for passwords; do not build password hashing manually.
  • Sodium provides modern cryptographic primitives, but application developers still need an appropriate protocol.
  • count() on non-countable values became a migration warning and later stricter behaviour.

Upgrade Review

  • Search for count() calls receiving nullable or mixed data.
  • Check password algorithm support on the target build.
  • Do not replace a domain interface with object merely because the broad type is available.

The practical upgrade work is usually finding loose assumptions in older code rather than adopting a new syntax feature.

Practice

Audit a Mixed Count

Review a function that calls count($records) where $records may be null. Decide whether to reject null, default it to an empty array, or model the type more accurately.

Show solution

Choose based on the domain. If absence means no records, normalise with $records ?? []. If absence signals a bug, add an array or Countable contract and fix the caller.