PHP 5.3: Major Features

PHP 5.3 is the first big modernization of the 5.x line: namespaces (namespace, use, fully qualified names), late static binding (static:: vs self::), closures (anonymous functions with use), a limited goto, NOWDOC (heredoc without variable interpolation), an optional garbage collector for reference cycles, Phar archives as applications, and a long list of extension and INI improvements (e.g. mysqlnd, intl, openssl updates). At the same time it tightens the language: call-time pass-by-reference is gone, several PHP 4-era patterns are deprecated (ereg*, old-style class constructors in some edge cases), and new reserved words can break unquoted constant names.

Treat migration53 as the authoritative split into new features, incompatible changes, and deprecated functionality.

Table of Contents


Namespaces

Namespaces isolate code and replace endless ClassName prefixes:

namespace App\Model;

use App\Db\Connection;
use SomeVendor\LoggerInterface;

class UserRepository
{
    public function __construct(private Connection $db, private LoggerInterface $log) {}
}

__NAMESPACE__, import aliases, and bracketed namespace blocks reduce collisions with global functions and legacy libraries.

Late static binding

static:: resolves to the called class in inheritance chains; self:: stays bound to the defining class. That fixes many “static helper” patterns that broke under PHP 5.2-style self::.

Closures (use)

Anonymous functions can capture variables by value or by reference:

$factor = 2;
$mul = function ($x) use ($factor) {
    return $x * $factor;
};

This is the backbone for callbacks before PHP 5.4 allowed $this in closures.

goto, NOWDOC, const outside classes

  • goto jumps to a label in the same function/method scope—use sparingly (state machines, generated parsers).
  • NOWDOC is like heredoc but does not parse $variables inside the block—ideal for regex-heavy or shell snippets.
  • const FOO = 1; at file scope (outside a class) is supported in namespaced files.

Garbage collection for cycles

gc_enable() / gc_disable() / gc_collect_cycles() let you reclaim objects that reference each other in cycles—important for long-running daemons and some ORM graphs.

Phar, intl, drivers

  • Phar: self-contained PHP apps and library distributions as .phar archives.
  • intl: ICU-based formatting and collation for real locales.
  • mysqlnd: native driver for mysql/mysqli/PDO_mysql with a cleaner memory model (when built with it).

See migration53 new features for the full list (including openssl, filinfo, pdo_sqlite, etc.).

Practical recipes

Prefer preg_* over ereg*

if (preg_match('/^[a-z]+$/i', $name)) { /* … */ }

Namespace legacy bootstrap

Wrap old code in namespaces gradually: one package at a time, use statements at the top of new files.

Backward incompatible changes

High-signal items (full detail: migration53 incompatible):

  • New reserved keywords (goto, namespace, use, …) can break constant names that were unquoted strings before—quote or rename.
  • Call-time pass-by-reference (foo(&$x)) is removed; use function definitions with &$param only.
  • mysql: mysql_list_dbs() and some helpers are deprecated—plan a mysqli/PDO path even before PHP 7 removes mysql entirely.
  • Windows / SAPI: e.g. ISAPI dropped; pick FastCGI or other supported SAPIs.
  • clearstatcache() parameter semantics and several parameter order cleanups across extensions—re-read the manual for functions you wrap.

Deprecated

  • ereg* POSIX regex family—migrate to preg_* with delimiters.
  • SQLite2 extension—move to SQLite3 / PDO_SQLITE.
  • mime_magic—use fileinfo instead.
  • Old-style var in classes (still works but discouraged in favor of visibility keywords in later versions).

Full list: migration53 deprecated.

Other notes

  • safe_mode and related ideas are on the way out—do not rely on them for security.
  • Review INI defaults and extension= lines when upgrading distro packages.

Closing thoughts

PHP 5.3 is where modern PHP really starts: namespaces and closures change how you structure projects. Clean up ereg* and call-time references, then later jumps to 5.4+ (traits, short arrays) and eventually PHP 7 become much easier.