php

  • filter_var validates better than the regex you were about to write

    Email and URL validation by regular expression is a well-known way to reject valid input. The correct pattern for an address is famously unreadable, and the shortened versions…

  • WP-Cron only runs when someone visits

    WP-Cron is not cron. It is a check performed on page load: if a scheduled task is overdue, WordPress fires a loopback request to run it. On a…

  • The Xdebug profiler tells you where, not why

    A profile answers “which functions consumed the time” precisely and says nothing about the reason. The most common finding is that the top entry is PDOStatement::execute, which is…

  • Migrating PSR-0 to PSR-4 removes a directory level

    PSR-0 mapped the entire namespace onto the path, so AppReportBuilder had to live at src/App/Report/Builder.php — the vendor and package name repeated inside a directory that was already…

  • PHPUnit data providers turn six tests into one

    Testing the same behaviour across several inputs usually produces six near-identical methods, and when the assertion needs changing it has to change six times. A data provider separates…

  • Composer prefer-dist and prefer-source are not interchangeable

    Composer can install a package either as a downloaded archive or as a git clone. The default depends on package metadata and on whether the version is a…

  • Filtering a WooCommerce catalogue without the meta tables

    Five filters over 30,000 variations, and a request that never returns. Replacing EAV meta joins with a denormalised index table kept in sync by product hooks.

  • Dependency injection works fine without a container

    Dependency injection is passing collaborators in rather than constructing them inside. A container is a tool for assembling those graphs automatically. The two get conflated so thoroughly that…

  • SplFixedArray when the array is large and the shape is known

    A PHP array is a hash table even when the keys are 0 to n. That flexibility costs memory — roughly three times what a plain C array…

  • __invoke turns an object into a callable

    A class with a single meaningful method usually ends up named after the verb — PriceFormatter::format() — and read as a stutter at every call site. __invoke() lets…