php / php/php-src

Lots of classes do not allow `__debugInfo()` overrides to work

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

まだ誰も着手していません。

Bug Status: Verified
主要言語
C
スター
40.4k
フォーク
8.1k
平均マージ
2日 13時間
マージ済み PR(30日)
96

説明

Description

Inspired by #11310, I wrote a quick test script to check if there were other classes where creating a subclass with a __debugInfo() method did not work. I found a number of such classes (the one seg fault I filed separately at #16316 since that is a bigger issue than the override just not working).

I tested against b675db4c56dd0de4ea1f5195d587ed90f0096ed8

I did not test against all extensions, `php -m` output provided
[PHP Modules]
bcmath
calendar
Core
ctype
curl
date
dba
dom
enchant
exif
FFI
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
intl
json
ldap
libxml
mbstring
mysqli
mysqlnd
odbc
openssl
pcntl
pcre
PDO
pdo_dblib
PDO_Firebird
pdo_mysql
PDO_ODBC
pdo_pgsql
pdo_sqlite
pgsql
Phar
posix
random
readline
Reflection
session
shmop
SimpleXML
snmp
soap
sockets
sodium
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tidy
tokenizer
xml
xmlreader
xmlwriter
xsl
zend_test
zip
zlib

Approach: create a custom subclass with an empty constructor, and a __debugInfo() method returning ['x' => 'y']. The var_dump() a new instance of that subclass and check the output.

I found 17 classes across the DOM and SimpleXML extension where doing this caused an exception to be thrown relating to invalid state, e.g.

<?php

class Demo extends DOMNode {
    public function __construct() {}
    public function __debugInfo(): array {
        return ['x' => 'y'];
    }
}

var_dump( new Demo() );
List of the 17 classes
DOMNode::class,
DOMNameSpaceNode::class,
DOMDocumentFragment::class,
DOMDocument::class,
DOMCharacterData::class,
DOMAttr::class,
DOMElement::class,
DOMText::class,
DOMComment::class,
DOMCdataSection::class,
DOMDocumentType::class,
DOMNotation::class,
DOMEntity::class,
DOMEntityReference::class,
DOMProcessingInstruction::class,

SimpleXMLElement::class,
SimpleXMLIterator::class,

I also found a further 20 classes where the override does not seem to work, across multiple extensions.

List of those classes
array (
  0 => 'DatePeriod',
  1 => 'DOMImplementation',
  2 => 'Dom\\Implementation',
  3 => 'DOMNodeList',
  4 => 'Dom\\NodeList',
  5 => 'DOMNamedNodeMap',
  6 => 'Dom\\NamedNodeMap',
  7 => 'Dom\\DtdNamedNodeMap',
  8 => 'Dom\\HTMLCollection',
  9 => 'IntlTimeZone',
  10 => 'IntlCalendar',
  11 => 'IntlGregorianCalendar',
  12 => 'IntlBreakIterator',
  13 => 'IntlRuleBasedBreakIterator',
  14 => 'IntlCodePointBreakIterator',
  15 => 'SplFixedArray',
  16 => 'mysqli',
  17 => 'mysqli_result',
  18 => 'mysqli_stmt',
  19 => 'XMLReader',
)

You can see the script I used at https://gist.github.com/DanielEScherzer/c979c15b47bc603758c4c38ba25dd510

PHP Version

dev-master

Operating System

No response

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

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

はじめの一歩

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

調査の方向性

リンクされている再現スクリプトとその var_dump チェックから始め、次に一覧にある DOM、SimpleXML、その他の影響を受けるクラスを調べてください。報告されているクラスで無効な状態の例外と機能しないオーバーライドを再現してください。__debugInfo() のサブクラスでの動作が、それらの例外なしに一貫して機能すれば完了です。

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

評価

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

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

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