note 128225 added to class.weakmap
| From: | malferov at gmail dot com | Date: | Fri, 17 Feb 2023 10:29:21 +0000 |
| Subject: | note 128225 added to class.weakmap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220181@lists.php.net to get a copy of this message | ||
<?php
$wp = new WeakMap();
// It's not working.
// Has no error but not adding dynamically specifying object to map;
// garbage collector will not be able to clear unnamed value, as I suppose
$wp[new stdClass()] = 'value';
echo $wp->count() . PHP_EOL; // 0
// It's working, as expected
$obj = new stdClass();
$wp[$obj] = 'value';
echo $wp->count(); // 1
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.13.130 (proxied: 89.178.148.121)
----
Manual Page -- https://php.net/manual/en/class.weakmap.php
Edit -- https://main.php.net/note/edit/128225
Del: integrated -- https://main.php.net/note/delete/128225/integrated
Del: useless -- https://main.php.net/note/delete/128225/useless
Del: bad code -- https://main.php.net/note/delete/128225/bad+code
Del: spam -- https://main.php.net/note/delete/128225/spam
Del: non-english -- https://main.php.net/note/delete/128225/non-english
Del: in docs -- https://main.php.net/note/delete/128225/in+docs
Del: other reasons-- https://main.php.net/note/delete/128225
Reject -- https://main.php.net/note/reject/128225
Search -- https://main.php.net/manage/user-notes.php