php / php/php-src

\Dom\DocumentFragment::getElementById() is not supported

オープン
#20,282 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

@ndossche がすでに取り組んでいます。

2025年10月24日 から。

  • #20284 @ndossche による — オープン
Extension: dom Feature Status: Verified
主要言語
C
スター
40.4k
フォーク
8.2k
平均マージ
2日 13時間
マージ済み PR(30日)
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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、リンクされたプルリクエストと、issue で言及されている既存の Dom\DocumentFragment::querySelector 実装を確認します。重複する ID と期待される検索動作を含む、getElementById() のセマンティクスについて DOM 仕様を参照してください。完了とは、メソッドが利用可能になり、仕様どおりに一致するフラグメント要素を返すことです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
c, php
領域
api
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。