Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121102 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 13621 invoked from network); 19 Sep 2023 07:58:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Sep 2023 07:58:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5E271180505 for ; Tue, 19 Sep 2023 00:58:27 -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 ; Tue, 19 Sep 2023 00:58:26 -0700 (PDT) Received: from smtpclient.apple (unknown [49.48.216.113]) by mail1.25mail.st (Postfix) with ESMTPSA id BD40E603CF; Tue, 19 Sep 2023 07:58:17 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) In-Reply-To: <39d49239-c87c-2c95-c293-f2952b5e3307@bastelstu.be> Date: Tue, 19 Sep 2023 14:58:04 +0700 Cc: Niels Dossche , PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: References: <29eb53a7-9aef-4e48-999e-97574f27a9df@gmail.com> <4C6FD028-4E34-4578-AF04-EDAC120E3E94@koalephant.com> <872B9392-D91A-45BC-8956-3E53B16723A6@koalephant.com> <39d49239-c87c-2c95-c293-f2952b5e3307@bastelstu.be> To: =?utf-8?Q?Tim_D=C3=BCsterhus?= 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 14:30, Tim D=C3=BCsterhus wrote: >=20 > Hi >=20 > On 9/19/23 08:35, Stephen Reay wrote: >> 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. >=20 > I was one of the persons who discussed this updated API with Niels in = private and looking up the discussion it was me who proposed making the = constructor private and just providing named constructors. >=20 > =46rom the perspective of the user of the API, I like the symmetry = between all the named constructors: >=20 > Whenever I want to create a new document, I use one of the fromXyz() = methods. And when I use those, I get exactly what it says on the tin. >=20 > Making the regular constructor available for use would effectively = make whatever that constructor does a special case / the default case. = This makes sense for DateTimeImmutable, because the __construct() = variant is likely much more often used than the various createFromXyz() = variants. For the HtmlDocument I find it less obvious that creating an = empty document would be the default case compared to loading an existing = document from a file. >=20 > We should probably rename the named constructors to include the = "create" prefix for consistency with DTI though. >=20 > Best regards > Tim D=C3=BCsterhus >=20 Hi Tim, Thanks for providing context on where this idea came from. The constructor + specialised factory methods pattern is not exactly new = in PHP (e.g. it took about 3 minutes to find multiple Symphony classes = doing this), and disabling the public constructor for purely cosmetic = reasons sounds like a very weird, and ironic choice to me, when the = stated goal is to make the API *less surprising* than the previous one. Cheers Stephen=20=