Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121101 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 10699 invoked from network); 19 Sep 2023 07:31:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Sep 2023 07:31:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0DBF31804C6 for ; Tue, 19 Sep 2023 00:31:03 -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,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS24940 176.9.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (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:31:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1695108660; bh=DZ6azT6ScA+I5378sEzjJxDSRAjhGG4yaFxSoeLkQLc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=ZRjdTIkVytzMvVKDK7UvPA+d8y1eDQ6frYFqtAw4S51c8B8hJXp5CfWqzV8KN9nwP JSau8rSJ3cPC1EFmFIZmybHqReitllStIltXHukuR1HKA5Qjt7ugX4O5tEDb8TVBNd 7W/XkxmifYsvmaWaKQR6retwVndO7hGhCLTpbnASAqeIAnQ1lvXAONoUdGJlsqgoMS nZiDer0VYRCOZG5C1vBxXo/LMmK9qrjagIJN0UIFldOla849pISTPokJgOPl7JqlRl kNHRY/t1WFhWhGLSdVtswnKIINIlSh2WgJzfK+GjcCOCKrTDhMFxtYPPyz23sR0J7n fLrijEkl/bBrg== Message-ID: <39d49239-c87c-2c95-c293-f2952b5e3307@bastelstu.be> Date: Tue, 19 Sep 2023 09:30:58 +0200 MIME-Version: 1.0 To: Stephen Reay , Niels Dossche Cc: PHP Internals References: <29eb53a7-9aef-4e48-999e-97574f27a9df@gmail.com> <4C6FD028-4E34-4578-AF04-EDAC120E3E94@koalephant.com> <872B9392-D91A-45BC-8956-3E53B16723A6@koalephant.com> Content-Language: en-US In-Reply-To: <872B9392-D91A-45BC-8956-3E53B16723A6@koalephant.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC] [Discussion] DOM HTML5 parsing and serialization support From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=c3=bcsterhus?=) Hi 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. > 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. From the perspective of the user of the API, I like the symmetry between all the named constructors: 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. 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. We should probably rename the named constructors to include the "create" prefix for consistency with DTI though. Best regards Tim Düsterhus