Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121105 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 50863 invoked from network); 19 Sep 2023 20:04:00 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Sep 2023 20:04:00 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8A6F71804AC for ; Tue, 19 Sep 2023 13:03:59 -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_H3,RCVD_IN_MSPIKE_WL,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-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (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 13:03:59 -0700 (PDT) Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-9a9d82d73f9so764360466b.3 for ; Tue, 19 Sep 2023 13:03:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695153838; x=1695758638; darn=lists.php.net; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=7uugdG8eAp1G3dtsMSjsYFsiO5h/t8U/s1NSFuuF7wM=; b=mJMrEFIekkXMsaKfxvqWpNBrO7NNLtvPewJh65gK+/c1ajz1HuMwiViFYzVB8S7s1T pnYv47vRiide7GhSiQ64wEG06wmUtsZgoREdf6AVfe2Es+yrDXoWhoR6PELZ7kjIpmPG b5cA+kQyo7JeXqXOit+mUV9Us+oRU4tt6P5GwT82ZW8KzYVFPX7K5QW5lxdumEU7aS/n EEZL14rDprKtLs1Kgqx3wHhr9bn4BRWfM4kHXZUTOoaK6ieqXgzep2WlaGQ2tIOa7FJp I4MvEo7oUQgqvM3Og4wtHf6VCkONGuD0CnaLH0OIxFKMXuiOmrAQADyE4wWPqGLSj5SB 6Rrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695153838; x=1695758638; h=content-transfer-encoding:in-reply-to:from:references:cc: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=7uugdG8eAp1G3dtsMSjsYFsiO5h/t8U/s1NSFuuF7wM=; b=cGC8uCRKxSzXz3xWl7kjrzjTIxR6AVKabn4yel8k8V6I8qILLYhBdxWsrTOrxkajPP vRcJLf+3NMoNglsBPJ+RgRglWPU06AQV6sb+AGrlCAqJiV5FSW3tHlQhfLQ7Ln1qHB6R bj6JaSgXlSvLiZZ8wfL6qaNuIIHjF/HAEqsPFwUMgZ08wldK2eIuivoTBlcJC0uz2RZn 3z8lvwqYBTOAipORlfWFW6buoxkhkD5MwEF1X6FfSUTpyG2nKBMNpj/r2XfzY9h2a9FL Aw5NQ8ue9yJf754e9U+1fVl2IC8hwlkRAgqtsxz4ifaWtGGJSgJifHg15w9neAzTly/r l++g== X-Gm-Message-State: AOJu0Yz6KFruj651Y/y3Isj2C63Umv0QnQ5gFwx+ceBUctqJ7PerDaB5 +ld8DPaMpNCz1G1afJZO0uA= X-Google-Smtp-Source: AGHT+IH/Sk7LPXgjwgkosbD0IXVgOUkMr1H1dgYou1Va7TSfpp0T1gheBYhOv+neP2g3W3dd1G+/Lg== X-Received: by 2002:a17:907:2c61:b0:9ad:7f8a:3720 with SMTP id ib1-20020a1709072c6100b009ad7f8a3720mr268131ejc.73.1695153837525; Tue, 19 Sep 2023 13:03:57 -0700 (PDT) Received: from ?IPV6:2a02:1811:cc83:ee50:280e:1e36:3a00:824? (ptr-dtfv08akcem5xburtic.18120a2.ip6.access.telenet.be. [2a02:1811:cc83:ee50:280e:1e36:3a00:824]) by smtp.gmail.com with ESMTPSA id m18-20020a1709066d1200b00993a37aebc5sm8223518ejr.50.2023.09.19.13.03.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Sep 2023 13:03:55 -0700 (PDT) Message-ID: Date: Tue, 19 Sep 2023 22:03:53 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Stephen Reay 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> <39d49239-c87c-2c95-c293-f2952b5e3307@bastelstu.be> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC] [Discussion] DOM HTML5 parsing and serialization support From: dossche.niels@gmail.com (Niels Dossche) Hi Stephen On 19/09/2023 09:58, Stephen Reay wrote: > > >> On 19 Sep 2023, at 14:30, Tim Düsterhus wrote: >> >> 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 >> > > 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. > Besides the points that have been mentioned by Tim and Larry, there's also the expectation of the programmer that migrates to the new classes to take into account. They're used to calling the constructor on the old class and calling a load method afterwards. As there is still a constructor, but no load method, this might be confusing for them. So in my opinion, disabling it makes it less surprising than the previous one. Also, just because Symfony does this doesn't mean it's automatically something we should follow. > > Cheers > > Stephen Kind regards Niels