Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121104 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 49200 invoked from network); 19 Sep 2023 19:56:47 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Sep 2023 19:56:47 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6A25E1804C6 for ; Tue, 19 Sep 2023 12:56:46 -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_H2,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-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (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 12:56:45 -0700 (PDT) Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-3214de9cd8bso2444884f8f.2 for ; Tue, 19 Sep 2023 12:56:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695153404; x=1695758204; darn=lists.php.net; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=P1AWwfRROiY4koxpxeMC+q2uiz996S3LrVG6efQ+/Mg=; b=iYJCS7IyERXpfn458ozBuJCshNsABg3ZdT51MO6HazhilQq6JWOP1u+/0/SvChdQ7c GynxXk2Sbq7kuzakZy4GBBMQnf871HY4TQpUtZ5ZSgV/YkZLaFx1yq2uRbv5XFFxpUNQ Lrz9a+nqfFF9J7Sh7oTajbyzFVlaBZQMfLH9Q7PhA1BHStTgGUXRAQUFnaC6T9LJozq9 vzJ2XOOjOBubhURMlf1EA1UBNy0y2wZBnIViUuBL1+5SkxSp7/NGkNoPsrl8uNZSmhuZ cP6Po+ufyHZK0s+0V1ZecRURlFBSlcnfbUL8vdeTXEiGc1B0AqL/QNwMqDhXC0BOU6ZJ r1Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695153404; x=1695758204; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=P1AWwfRROiY4koxpxeMC+q2uiz996S3LrVG6efQ+/Mg=; b=C4ICYJbFbbqn+xmLx3+znUWsNoHZm/58qwCGlbGtJDJ+59AeovMFX7PRUfYhFNcGep DRZxiG/jq+/fsS+RMIfo7Da4l9YfqyD/Dvy034bMBRcwFmGmUevGRDnEtkSpRe5Np8mb zvP5boEAw+nAQOlCepEkejWK4Dx46Z+r22L/0pzEuA/mRxEt6af8oEujXmLV6iLub+am sPt2WFwJ6gLVw9HI2o2uKRmA8Gly28w+OE0zTp0sL+DhCIMx9cuPrBxoqoBpgjBPKfte SQs0rZQfzkkxqfbcL1tVjU0oMPxGHucXuuPbqFh/H3G2G/br+L3H4UsNr8Qup+uEmYLY Z0LA== X-Gm-Message-State: AOJu0YyB09kRTrexnScwx8sKpG5G+m21j0JhWYvs1FN0bhHuES2bYzL2 LSLVDMy4mLPDgX5OY+qoytkC7othzFc= X-Google-Smtp-Source: AGHT+IEabr2SD9X/VLY9Z9yOOafA2mnpePbZVJY6IKDS5tApvp9HsKkQOxsaAIPeYowOR3G+6vmwFg== X-Received: by 2002:a5d:500d:0:b0:314:46af:e1e7 with SMTP id e13-20020a5d500d000000b0031446afe1e7mr576650wrt.34.1695153404113; Tue, 19 Sep 2023 12:56:44 -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 qq7-20020a17090720c700b009920a690cd9sm8183880ejb.59.2023.09.19.12.56.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Sep 2023 12:56:43 -0700 (PDT) Message-ID: Date: Tue, 19 Sep 2023 21:56:42 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird 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> Content-Language: en-US In-Reply-To: <872B9392-D91A-45BC-8956-3E53B16723A6@koalephant.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 08:35, Stephen Reay wrote: > >> On 19 Sep 2023, at 01:00, Niels Dossche >> >> Cheers >> Niels >> >> -- >> 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) > > 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). > I don't really understand this part. What kind of meta-programming are you thinking of? Can you give an example? Calling the create methods on the abstract type does not seem sensible, because the input data is not interchangeable between the two subclasses. E.g. passing an XML input into HTMLDocument will not go well (and vice versa). So it seems to me that you need to know the type to be able to give sensible input. > > 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 agree with what Tim and Larry have said here. I do agree too that it should be called createFromString and createFromFile to be consistent with the DateTime classes. And perhaps instead of createFromEmpty it should be createEmpty because you're not creating an instance "from" something here, you're creating it with "nothing". > > Cheers > > Stephen > Kind regards Niels