WeakMap::offsetExists return false if value is null
Open
@Girgias is already working on this.
Since Mar 8, 2024.
Bug
Category: Engine
Status: Needs Triage
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
The following code:
<?php
$wm = new \WeakMap;
$os = new \SplObjectStorage;
$obj1 = new \stdClass;
$obj2 = new \stdClass;
$wm[$obj1] = null;
$wm[$obj2] = true;
$os[$obj1] = null;
$os[$obj2] = true;
var_dump($wm->offsetExists($obj1));
var_dump($wm->offsetExists($obj2));
var_dump($os->offsetExists($obj1));
var_dump($os->offsetExists($obj2));
foreach ($wm as $key => $value) {
if ($key === $obj1) {
echo 'key $obj1 is always here';
}
}
Resulted in this output:
bool(false)
bool(true)
bool(true)
bool(true)
key $obj1 is always here
But I expected this output instead:
bool(true)
bool(true)
bool(true)
bool(true)
key $obj1 is always here
PHP Version
PHP 8.1.5
Operating System
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.