SimpleXML: empty child element without attributes casts to true instead of false
Đang mở
Bug
Extension: simplexml
Status: Verified
- Ngôn ngữ chính
- C
- Star
- 40.4k
- Fork
- 8.1k
- Merge trung bình
- 2 ngày 13 giờ
- Pull request đã merge (30 ngày)
- 96
Mô tả
The following code:
<?php
$cases = [
'<foo><bar>content</bar></foo>',
'<foo><bar/></foo>',
'<foo/>',
];
foreach ($cases as $case) {
\printf("%-30s: %s\n", $case, new \SimpleXMLElement($case)->bar ? '✅' : '❌');
}
Resulted in this output:
<foo><bar>content</bar></foo> : ✅
<foo><bar/></foo> : ✅
<foo/> : ❌
But I expected this output instead:
<foo><bar>content</bar></foo> : ✅
<foo><bar/></foo> : ❌
<foo/> : ❌
The documentation explicitly lists empty SimpleXML elements without attributes as falsy.
https://www.php.net/manual/en/language.types.boolean.php#language.types.boolean.casting
PHP Version
any
Operating System
Debian 13
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Đánh giá
Issue này chưa được đánh giá.