Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121100 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 6384 invoked from network); 19 Sep 2023 06:36:08 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Sep 2023 06:36:08 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DD92E1804C6 for ; Mon, 18 Sep 2023 23:36:07 -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=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS17378 206.123.64.0/18 X-Spam-Virus: No X-Envelope-From: Received: from mail1.25mail.st (mail1.25mail.st [206.123.115.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 18 Sep 2023 23:36:07 -0700 (PDT) Received: from smtpclient.apple (unknown [49.48.216.113]) by mail1.25mail.st (Postfix) with ESMTPSA id 1675D604A8; Tue, 19 Sep 2023 06:36:01 +0000 (UTC) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) In-Reply-To: Date: Tue, 19 Sep 2023 13:35:48 +0700 Cc: PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: <872B9392-D91A-45BC-8956-3E53B16723A6@koalephant.com> References: <29eb53a7-9aef-4e48-999e-97574f27a9df@gmail.com> <4C6FD028-4E34-4578-AF04-EDAC120E3E94@koalephant.com> To: Niels Dossche X-Mailer: Apple Mail (2.3731.700.6) Subject: Re: [PHP-DEV] [RFC] [Discussion] DOM HTML5 parsing and serialization support From: php-lists@koalephant.com (Stephen Reay) > On 19 Sep 2023, at 01:00, Niels Dossche=20 >=20 > Cheers > Niels >=20 > --=20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php (Resending with history removed due to apparent size limit)=20 Hi Niels, Obviously, a method with different signatures (`fromEmptyDocument`) = can't be in the parent, and I'll discuss that below, but having the = other factory methods that do have the same signature in parent (even if = only an abstract method, forcing concrete implementations to define it) = means that it's possible to *safely* do meta-programming with these = classes, where you load a string/file, using a classname from a = variable. This use-case doesn't necessarily need to know which specific = instance it's getting back, so long as it's an instance of the base = class (or interface, if it had been one), but that information can still = be presented, via the return type (either `static`, or `self` on the = parent and the actual class name on each of the implementations). Regarding the private constructor: I understand the issue with the *old* = class being confusing - but your new class doesn't have that issue, = because there are no "loadXXX" methods: as you said, if you're loading = an existing document, you're forced to do it via the static factory = methods. With that change alone, there's zero risk of confusion in = allowing direct constructor calls, because once the object is = instantiated there is no subsequent way to load a document and = inadvertently change the encoding. Having a regular constructor and then one or more factory methods for = specific cases is already a concept in PHP (i.e. DateTime[Immutable]'s = `createFromXXX` as well as a constructor), and IMO needing to call a = factory method to get an "empty" document seems out of place in PHP - it = seems a bit like a Java-ism - using a factory, where one just isn't = required. Cheers Stephen