note 129116 added to class.weakmap

From: Date: Fri, 22 Dec 2023 06:17:47 +0000
Subject: note 129116 added to class.weakmap
Groups: php.notes 
Request: Send a blank email to php-notes+get-221070@lists.php.net to get a copy of this message
Came up with an interesting use case. To get callback when a variable is destroyed. <?php class User { public function __construct(private $name) { $this->name = $name; echo "Constructing {$this->name}\n"; } public function getName() { return $this->name; } public function __destruct() { echo "Destructing {$this->name}\n"; } } class Observabler { private $name; public function __construct(User $u) { $this->name = $u->getName(); echo "Constructing Observabler for {$this->name}\n"; } public function __destruct() { echo "Destructing Observabler for {$this->name}\n"; } } ?> Output: Constructing Test Constructing Observabler for Test Destructing Test Destructing Observabler for Test End ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.157.134 (proxied: 208.127.95.104) ---- Manual Page -- https://php.net/manual/en/class.weakmap.php Edit -- https://main.php.net/note/edit/129116 Del: integrated -- https://main.php.net/note/delete/129116/integrated Del: useless -- https://main.php.net/note/delete/129116/useless Del: bad code -- https://main.php.net/note/delete/129116/bad+code Del: spam -- https://main.php.net/note/delete/129116/spam Del: non-english -- https://main.php.net/note/delete/129116/non-english Del: in docs -- https://main.php.net/note/delete/129116/in+docs Del: other reasons-- https://main.php.net/note/delete/129116 Reject -- https://main.php.net/note/reject/129116 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221070) next »