PHP Has WeakMap Too - and It Fixes Per-Object Caching
Caching computed data per object with static arrays pins those objects in memory forever - a leak with a cache's haircut. PHP 8's WeakMap caches without owning.
Step-by-step programming tutorials on PHP, JavaScript, Laravel, WordPress and more.
Caching computed data per object with static arrays pins those objects in memory forever - a leak with a cache's haircut. PHP 8's WeakMap caches without owning.
Store state against DOM nodes, cache per-object computations, keep private data - WeakMap does all three and lets the garbage collector clean up behind you.
file() and fetchAll() load everything into RAM and die on big datasets. Generators stream one row at a time with constant memory - and the code barely changes.
AbortController is not just for fetch(). Pass its signal to addEventListener and you can remove dozens of listeners with a single abort() call - no more keeping references to bound functions.