Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121076 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 46203 invoked from network); 16 Sep 2023 23:43:24 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Sep 2023 23:43:24 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 729B01804AC for ; Sat, 16 Sep 2023 16:43:22 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 16 Sep 2023 16:43:22 -0700 (PDT) Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-9adb9fa7200so652162766b.0 for ; Sat, 16 Sep 2023 16:43:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694907800; x=1695512600; darn=lists.php.net; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=uYAKo8hNbP6Cfyeyg0w92nj3LD2ZA4J58rOlY83mB0M=; b=mtgvSJv500Zuox35+BYQBoUeg0irp1lGRjtDTrwG9SaJ4iehd4pv4hiksP83ihIx8N nXkUGK8F3FpZ8yTp18tOTrziP9fOcwtFyGB4NC6ypRY4JjX0Wfi5tg1bNhcmpSKuVO19 Zh8+dgEjGj1WYXMtMLf029ZYZ8SY+Wxay++u7MwWpkpcxKobVyHzNnxmOmbi/m28b2Y5 zoksSsraG2YkCbtUimyO5HfjSkQVw7mOk3TiLLh96lMvPvL4i/U46wIQQ6o51u1jaGOp WSokNidjMwGI2esftjmWlpVHuo/rlA2YjLXE1JwtOUj8ifvadtYw4x7UqA55Y1cChxQZ Of3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694907800; x=1695512600; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uYAKo8hNbP6Cfyeyg0w92nj3LD2ZA4J58rOlY83mB0M=; b=Rx4qOKkWypBh03WZ5RZg5mTSXquoTLH2PwyJPPv9i2lVq20Khc7DvCZ5f4G3zsHfcD wmmRGlZ6dlGuVaa/IUfvYBII0ElXNJVbS9AAp4FC9eldR+7lBJ7j1nEWS1jolIDGvmDS TZGuhChVZaYTqlxvs9SwICe5Uvsms+A4SkV5bhrxEoN3rcRPSvaP8JvnsTtBGmI7gh0U 66zNhDUcHEfNuPmkxL5pfISLmkha071uuzqREPGWal8oGFhLQxMWLdeSUbIgrRL39wDN e2WfOolntK2+MEbrkqWig7KVACkBIYbKud445jdAeW4Fl33hS89AVRoWFnJC0VvgjQpH X6BA== X-Gm-Message-State: AOJu0YwWmN2YoSKIsmPo2lj6jcxYv7kwrFVOj2sABuxkz6zulE0RoMPI dofvDP0abXPpYRVy2YL1ULy+UGC/9eI= X-Google-Smtp-Source: AGHT+IGKlMjvU3HkTgbjJ/z/kPev7J9eVm43dJJvYNbFO45JrXplPn1JiyGe8EUOAKzxttgoypZCkA== X-Received: by 2002:a17:907:6d20:b0:9a1:fed1:9b42 with SMTP id sa32-20020a1709076d2000b009a1fed19b42mr11977706ejc.23.1694907800277; Sat, 16 Sep 2023 16:43:20 -0700 (PDT) Received: from [192.168.0.59] (178-117-137-225.access.telenet.be. [178.117.137.225]) by smtp.gmail.com with ESMTPSA id cf20-20020a170906b2d400b0099bd453357esm4260271ejb.41.2023.09.16.16.43.19 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 16 Sep 2023 16:43:19 -0700 (PDT) Message-ID: <8f8bf3de-428f-4de3-be48-416ca1f28a14@gmail.com> Date: Sun, 17 Sep 2023 01:43:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: [RFC] [Discussion] DOM HTML5 parsing and serialization support From: dossche.niels@gmail.com (Niels Dossche) Hi Larry On 9/17/23 01:04, Larry Garfield wrote: > On Fri, Sep 15, 2023, at 6:17 PM, Niels Dossche wrote: >> On 9/2/23 21:41, Niels Dossche wrote: >>> Hello internals >>> >>> I'm opening the discussion for my RFC "DOM HTML5 parsing and serialization support". >>> https://wiki.php.net/rfc/domdocument_html5_parser >>> >>> Kind regards >>> Niels >> >> >> Hi internals >> >> I'd like to announce a change to the RFC. The new RFC version is 0.5.1, >> the old one was 0.4.0. >> The diff can be viewed via the revision history button on the right. >> >> I had a productive discussion with Tim and Arne about the class hierarchy. >> Here's a summary of the changes and the rationale. >> >> Until now, the RFC specified that DOM\HTML5Document extends DOMDocument. >> However, as we're introducing a new class anyway, we believe we should >> take the opportunity to improve the API. >> We have the following concerns: >> a) It's a bit of an awkward class hierarchy. *If* we hypothetically >> would want to get rid of DOMDocument in the far far future, we can't >> easily do that. >> b) API is messy. Some methods are useless for HTML5Document. E.g.: >> validate(), loadXML(), loadXMLFile(). They can be a source of confusion. >> c) The fact that you can pass HTML5Document to methods accepting >> DOMDocument may result in unexpected behaviour when the method expects >> a particular behaviour. It would be better if developers could "opt-in" >> to accepting both DOMDocument and HTML5Document in a method using a >> common base class. >> d) The properties set by DOMDocument's constructor are overridden by >> load methods, which is surprising. That's even mentioned as the second >> top comment on https://www.php.net/manual/en/domdocument.loadxml.php. >> Furthermore, the XML version argument of the constructor is even >> useless for HTML5 documents. >> >> So we propose the following changes to the RFC. >> >> We'll add a common abstract base class DOM\Document (name taken from >> the DOM spec & Javascript world). >> DOM\Document contains the properties and abstract methods common to >> both HTML and XML documents. >> Examples of what it includes/excludes: >> * includes: firstElementChild, lastElementChild, ... >> * excludes: xmlStandalone, xmlVersion, validate(), ... >> Then we'll have two subclasses: DOM\HTMLDocument (previously we called >> this DOM\HTML5Document) and DOM\XMLDocument. We dropped the 5 from the >> name to be more resilient to version changes and match the DOM spec >> name. >> DOMDocument will also use DOM\Document as a base class to make it >> interchangeable with the new classes. >> >> The above would solve points a, b, and c. >> To solve point d, we can use "factory methods": >> This means HTMLDocument's constructor will be made private, and instead >> we'll have three static methods that create a new instance: >> - HTMLDocument::fromHTMLString(string $xml): HTMLDocument; > > That should be string $html, yes? Indeed, silly copy paste mistake on my part. In fact, the bullet point list is a bit outdated: it uses an older proposed method name (i.e. it says fromHTMLString instead of fromString; the HTML part is unnecessary duplication as the method is in the HTMLDocument class). I forgot to update that in my email draft when the final name was decided. Anyway, the code snippet from my email and the RFC text both have the right method name and parameter name. > >> - HTMLDocument::fromHTMLFile(string $filename): HTMLDocument; >> - HTMLDocument::fromEmptyDocument(string $encoding="UTF-8"): >> HTMLDocument; >> >> >> Or to put it in PHP code: >> >> ``` >> namespace DOM { >> // The base abstract document class >> abstract class Document extends DOM\Node implements DOM\ParentNode { >> /* all properties and methods that are common and sensible for both >> XML & HTML documents */ >> } >> >> class XMLDocument extends Document { >> /* insert specific XML methods and properties (e.g. xmlVersion, >> validate(), ...) here */ >> >> private function __construct() {} >> >> public static function fromEmptyDocument(string $version = "1.0", >> string $encoding = "UTF-8"); >> public static function fromFile(string $path); >> public static function fromString(string $source); >> } >> >> class HTMLDocument extends Document { >> /* insert specific Html methods and properties here */ >> >> private function __construct() {} >> >> public static function fromEmptyDocument(string $encoding = "UTF-8"); >> public static function fromFile(string $path); >> public static function fromString(string $source); >> } >> } >> >> class DOMDocument extends DOM\Document { >> /* Keep methods, properties, and constructor the same as they are now */ >> } >> ``` >> >> We're only adding XMLDocument for completeness and API parity. It's a >> drop-in replacement for DOMDocument, and behaves the exact same. >> The difference is that the API is on par with HTMLDocument, and the >> construction is designed to be more misuse-resistant. >> DOMDocument will NOT change, and remains for the foreseeable future. >> >> We also have to change the $ownerDocument field in DOMNode to have type >> ?DOM\Document instead of ?DOMDocument. >> Problem is that this breaks BC (but only a minor break): >> https://3v4l.org/El7Ve. >> Overriding properties is kind of useless, but if someone does it, then >> the compiler will complain loudly during compilation and it should be >> easy to fix. >> >> >> Of course, these changes means that the discussion period will run a >> bit longer than originally foreseen. >> >> Kind regards >> Niels > > > This all makes sense to me, and I like this as a way forward. Nice work! > > --Larry Garfield > Glad to hear that :) Cheers Niels