haphpiness

These are things in PHP which make me genuinely_happy();

Arrow Functions

PHP 7.4 introduced short closures with the fn keyword. They automatically capture variables from the parent scope (no use() needed), have implicit returns, and are perfect for callbacks.

// Before: verbose closure with explicit `use`
$doubled = array_map(function ($n) {
    return $n * 2;
}, $numbers);

// After: clean, concise, readable
$doubled = array_map(fn($n) => $n * 2, $numbers);

// Parent scope is captured automatically
$tax = 0.21;
$withTax = array_map(fn($price) => $price * (1 + $tax), $prices);

// Great for sorting
usort($users, fn($a, $b) => $a->name <=> $b->name);

// Chain beautifully
$result = array_filter(
    array_map(fn($u) => $u->getProfile(), $users),
    fn($p) => $p->isActive(),
);

Arrow functions don't replace regular closures — they complement them. Use fn for simple transforms and predicates, full closures for multi-line logic. The language gives you both tools and lets you choose.

Significance: Ergonomics

Reducing syntactic overhead for common patterns makes functional-style code practical. When a callback fits on one line, it should only take one line to write. Arrow functions made PHP's array functions genuinely pleasant to use.