php / php/php-src

WeakMap::offsetExists return false if value is null

Đang mở
#8,437 11 bình luận 0 reaction 1 người được giao Xem trên GitHub

@Girgias đang làm issue này rồi.

Từ ngày 8/3/2024.

Bug Category: Engine Status: Needs Triage
Ngôn ngữ chính
C
Star
40.4k
Fork
8.2k
Merge trung bình
2 ngày 13 giờ
Pull request đã merge (30 ngày)
96

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.