5 parts · Read in order

Values and memory

What a PHP value is made of, what it costs to hold one, and when the engine decides to copy it.

  1. What a PHP variable actually is

    A zval is sixteen bytes, a value union and a type tag. What that tag says decides whether an assignment copies anything, what a reference costs, and which variable pays.

    Part 111 min read

  2. A by-reference foreach leaves a reference in every element

    Walking an array with foreach ($rows as &$row) wraps every element in a zend_reference. On a million integers that is 32 MB the loop never gives back.

    Part 29 min read

  3. Two hundred thousand objects, and the collector never ran

    Two hundred thousand objects created and dropped, and zero collections. What puts an object in the root buffer, and why the collector's cost is set by what you keep alive.

    Part 312 min read

  4. A declared property is cheaper than an array key

    One hundred thousand four-field records cost 143.54 bytes each as objects and 397.14 as associative arrays. Where the crossover is, and what one undeclared property costs.

    Part 49 min read

  5. Appending to a string is free until someone else holds it

    The same .= statement took 0.269 ms and 218.836 ms in two loops that differ by one assignment. What a zend_string costs, where literals live, and why implode is not the fix.

    Part 58 min read

Arrow keys to move, Enter to open.