oop

  • get_id() rather than ->id, and why it matters

    The getter looks like ceremony over a property and is the entire point of the release: with the read going through a method, where the value comes from…

  • Laravel 5.5 and the packages that install themselves

    The first release where installing a package is one command. Auto-discovery removes two config edits per package, and hides the fact that they happened.

  • Custom collection classes on a model

    Behaviour that belongs to a set rather than to a single record — the total of a group of order lines, whether any of them is backordered —…

  • Class constant visibility, at last

    Every class constant has been public since constants existed, so an internal lookup table intended as an implementation detail was part of the public API whether or not…

  • Parameter type widening in 7.2

    A child class could never remove a parameter type from a method it overrides, even though accepting more than the parent is safe by the same rule that…

  • wc_get_order returns different classes for different types

    An order, a refund and a subscription are all shop_order-ish posts and are not the same class, so code type-hinting WC_Order breaks the first time a refund arrives.…

  • wp-cli commands are classes, and yours can be too

    A maintenance task run through wp eval-file has no arguments, no help, no progress and no exit code worth checking. Registering it as a command costs about ten…

  • Read a JSON config file with a fallback in PHP

  • The 7.2 object type hint, and what it is not

    November’s release adds object as a type, which sounds like it should let a function accept “any class” and be checked. It does exactly that and nothing more.…

  • iterable accepts an array or a Traversable

    Type-hinting array rejects a generator, and hinting Traversable rejects an array — so a function meant to consume a sequence either had no hint or forced the caller…