\Dom\DocumentFragment::getElementById() is not supported
未关闭
Extension: dom
Feature
Status: Verified
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.2k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
Description
The following code:
<?php
$d = \Dom\HTMLDocument::createFromString('<p id="a">b</p><p id="a">c</p>');
$df = $d->createDocumentFragment();
$df->getElementById('a');
Resulted in this output:
Error Call to undefined method Dom\DocumentFragment::getElementById().
But I expected this output instead:
(no output)
This method is present in the DOM spec: https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment/getElementById and the similar method ::querySelector is implemented; I can't tell if querySelector actually uses the ID index though or does a linear scan through the fragment. (Aka, this method should not just be implemented, it is expected to have O(1) performance.)
PHP Version
PHP 8.4.13 (cli) (built: Oct 1 2025 20:34:15) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.4.13, Copyright (c) Zend Technologies
with Zend OPcache v8.4.13, Copyright (c), by Zend Technologies
Operating System
Ubuntu 24.04.1
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先查看链接的 pull request,以及 issue 中提到的现有 Dom\DocumentFragment::querySelector 实现。参考 DOM 规范中关于 getElementById() 语义的说明,包括重复 ID 和预期的查找行为;完成的标准是该方法可用,并按规范返回匹配的 fragment 元素。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, php
- 领域
- api
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100