note 129050 added to class.weakmap

From: Date: Fri, 17 Nov 2023 10:18:21 +0000
Subject: note 129050 added to class.weakmap
Groups: php.notes 
Request: Send a blank email to php-notes+get-221005@lists.php.net to get a copy of this message
PHP's implementation of WeakMap allows for iterating over the contents of the weak map, hence it's important to understand why it is sometimes dangerous and requires careful thought. If the objects of the WeakMap are "managed" by other services such as Doctrine's EntityManager, it is never safe to assume that if the object still exists in the weak map, it is still managed by Doctrine and therefore safe to consume. Doctrine might have already thrown that entity away but some unrelated piece of code might still hold a reference to it, hence it still existing in the map as well. If you are placing managed objects into the WeakMap and later iterating over the WeakMap (e.g. after Doctrine flush), then for each such object you must verify that it is still valid in the context of the source of the object. For example assigning a detached Doctrine entity to another entity's property would result in errors about non-persisted / non-managed entities being found in the hierarchy. ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.157.134 (proxied: 124.122.125.1) ---- Manual Page -- https://php.net/manual/en/class.weakmap.php Edit -- https://main.php.net/note/edit/129050 Del: integrated -- https://main.php.net/note/delete/129050/integrated Del: useless -- https://main.php.net/note/delete/129050/useless Del: bad code -- https://main.php.net/note/delete/129050/bad+code Del: spam -- https://main.php.net/note/delete/129050/spam Del: non-english -- https://main.php.net/note/delete/129050/non-english Del: in docs -- https://main.php.net/note/delete/129050/in+docs Del: other reasons-- https://main.php.net/note/delete/129050 Reject -- https://main.php.net/note/reject/129050 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221005) next »