Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121103 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 42473 invoked from network); 19 Sep 2023 17:43:15 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Sep 2023 17:43:15 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 59C301804B0 for ; Tue, 19 Sep 2023 10:43:14 -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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS29838 64.147.123.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 19 Sep 2023 10:43:13 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 576B43200319 for ; Tue, 19 Sep 2023 13:43:12 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute4.internal (MEProxy); Tue, 19 Sep 2023 13:43:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm2; t=1695145391; x=1695231791; bh=9DIZ3vtSPZ 2/1InaO6yIYbhf0uYaOuww2KmCTv0iMWE=; b=o061qYjE9W+Qq4FiqmK5JCSGuo T1donavdEHIHs50w9s8BTOg6AiEipsNVWFJG3kte4oeGTpxXDrUW+Qz/nr8kIabA lK7y3v+chgq/I/Yxidm77YHeV4MdjuAlE+4ZY44kiZJT3f9gW57thg61rTkWVmr/ h3HEd518s8FyXTsoGSwFUhe0ZJ0oei0Ny4iOy4qsQzGn73zhDCE+PglPeUkilqgy /ETp6orLkbfMd55Znq25F48nO/9gsC4Lb0hccN+Nat8gLFEPDFsDgklVUEzzkNVG 7w0QxBzkOh7vOm7pDoNnohUgTR0qvG6ezwrq9ZtTynAUjO9HD69OdgWGvgFQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1695145391; x= 1695231791; bh=9DIZ3vtSPZ2/1InaO6yIYbhf0uYaOuww2KmCTv0iMWE=; b=V 5OvPOe8T9sv2Nk+XB6FEQjbGOoKpLAe01sHxyN3tqdr+Ok+of8p/KBV4YHStADKa LzaFt2QP32v8dEUwxWA7UOS26BleDD515WLgle9I7yd8KzPzPEpAfPWcINtyMDdm cp4J4XUNXx3Va/VICBDxQC2c60Xh+zJc0y06+AoxNCFGmnSWYTq5MILMh+NtThvr HX6mWnfmQbl3z9c7hypQPCyW4Nln46kyAljIy/Slvvex76PtaMIjC+cxZFaQtWcM L6p6FOH9SY8uM9oBtlSjKGoZfbKHZkiQ6JJoBlJKsDfnSlhaBxWTKesR4ItbyRoL Xs39A8YUgA2kCgQe/oMFA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudekuddgkeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepffffffejffdugfegvedviedttedvgfejffefffej leefjeetveehgefhhfdvgfelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 9DB591700093; Tue, 19 Sep 2023 13:43:11 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-761-gece9e40c48-fm-20230913.001-gece9e40c MIME-Version: 1.0 Message-ID: <5fe167d3-ceab-4ba5-8f33-6cb1c380c195@app.fastmail.com> In-Reply-To: <39d49239-c87c-2c95-c293-f2952b5e3307@bastelstu.be> 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> Date: Tue, 19 Sep 2023 17:42:50 +0000 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] [Discussion] DOM HTML5 parsing and serialization support From: larry@garfieldtech.com ("Larry Garfield") On Tue, Sep 19, 2023, at 7:30 AM, Tim D=C3=BCsterhus wrote: > Hi > > On 9/19/23 08:35, Stephen Reay wrote: >> Regarding the private constructor: I understand the issue with the *o= ld* 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 a= n existing document, you're forced to do it via the static factory metho= ds. With that change alone, there's zero risk of confusion in allowing d= irect constructor calls, because once the object is instantiated there i= s no subsequent way to load a document and inadvertently change the enco= ding. >>=20 >> 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 fa= ctory method to get an "empty" document seems out of place in PHP - it s= eems a bit like a Java-ism - using a factory, where one just isn't requi= red. >>=20 > > I was one of the persons who discussed this updated API with Niels in=20 > private and looking up the discussion it was me who proposed making th= e=20 > constructor private and just providing named constructors. > > From the perspective of the user of the API, I like the symmetry=20 > between all the named constructors: > > Whenever I want to create a new document, I use one of the fromXyz()=20 > methods. And when I use those, I get exactly what it says on the tin. > > Making the regular constructor available for use would effectively mak= e=20 > whatever that constructor does a special case / the default case. This=20 > makes sense for DateTimeImmutable, because the __construct() variant i= s=20 > likely much more often used than the various createFromXyz() variants.=20 > For the HtmlDocument I find it less obvious that creating an empty=20 > document would be the default case compared to loading an existing=20 > document from a file. > > We should probably rename the named constructors to include the "creat= e"=20 > prefix for consistency with DTI though. > > Best regards > Tim D=C3=BCsterhus I agree with Tim here. If you have named constructors that are all "equ= ally common," then it's non-obvious which one should be the "unnamed def= ault." I know that `fromX()` requires an X, `fromY()` requires a Y, but= what does `__construct()` require? I cannot tell from the call site. = If __construct() is just an alias of on of the fromX() methods, then wha= t purpose does it serve other than confusion? In addition, although it's probably not super relevant here, static fact= ory methods are chainable in a way that `new` is not. No extra parens a= re necessary. For classes I'm creating at hoc (rather than services tha= t are always managed via DI), I often prefer a named constructor just fo= r convenience. I don't see it as a Java-ism at all. Java is (in)famous for excessive l= ayers of factory classes, which is something different than what is goin= g on here. (How fair that reputation is in 2023, I don't know.) This i= s just "named constructors," which has been a reasonably common pattern = in PHP land for a long time. --Larry Garfield