oop

  • Closure::fromCallable turns a string into a closure

    PHP has several callable syntaxes — a string, an array of object and method, an invokable — and functions accepting callable have to tolerate all of them. Converting…

  • WooCommerce 3.0 turned products into objects

    Every plugin reading _price from post meta is now reading a private field. The mechanical half, the half that is not, and the compatibility layer for code you…

  • Multi-catch for two exceptions with one handler

    Handling two unrelated exceptions the same way meant either duplicating the catch block or introducing a common interface for the sole purpose of catching them together. The variable…

  • An entity has identity; a value object does not

    Two customers with the same name are different customers; two amounts of 49.00 TRY are the same amount. That distinction decides equality, mutability and whether the thing needs…

  • An async function always returns a promise

    Marking a function async changes its return value regardless of what the body does, which is obvious stated plainly and is the source of most confusion about them.…

  • Static analysis on a codebase that has never had any

    Four thousand errors on the first run is a number nobody can act on. Starting at level 0, ignoring by pattern, and raising the floor one level at…

  • Closure::call binds a closure without bindTo

    Running a closure in the scope of an object took two steps: bindTo() to produce a new closure, then invoking it. call() does both, and it is considerably…

  • PHP 7 replaced most fatals with an Error you can catch

    Calling a method on null used to end the request with a fatal that no handler could intercept, which is why every framework had a register_shutdown_function checking error_get_last().…

  • Map keeps insertion order and takes objects as keys

    A plain object as a lookup coerces every key to a string, so 1 and “1” collide, and an object key becomes the useless string [object Object]. Map…

  • Generators can return a value as well as yield

    A generator yields a sequence, and until PHP 7 that was all it could produce — so a function streaming rows had no way to also report how…