Post #2195231
2025-09-17 09:52 UTC
@dgoosens@phpc.social it works because Enum are « persistent », isn’t it? Because WeakMap doesn’t prevent the object to be destroyed. Wouldn’t SplObjectStorage be a safer choice ? Do you see other advantages in WeakMap for your use case? 🤔
Anyway, thanks for sharing 🙂
Replies (1)
-
@dgoosens@phpc.social 2025-09-17 11:58
@b_viguier@phpc.social yes... there is a difference in the way the Garbage Collection works in theory, if I am to unset an object that is used as key, I think I prefer the Weakmap approach, where it also removes the entry from the map BUT... and this I did not know... when using an ENUM, the behavior is the same in both cases and the entry in the maps are preserved: see here: https://3v4l.org/tpnsc#v8.4.12