A little memoize function in PHP

1 · Amit Merchant · March 17, 2023, 11:38 a.m.
So, Caleb Porzio recently shared a little memoize function in PHP. What the function does is pretty straightforward. It caches the result of a function call and returns the cached result if the function is called again with the same arguments. Here’s the function. function memoize($target) { static $memo = new WeakMap; return new class ($target, $memo) { function __construct( protected $target, protected &$memo, ) {} function __call($met...