Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123196 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id E65EA1A009C for ; Wed, 24 Apr 2024 08:23:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1713947021; bh=gOF5yGThhqbetv5YJdDBsUDbr4CKoBgRfgojX9Mqnkk=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=LRepHPJTWMUNgmy1bLH9jj4AwyAbBTYJnKIpJoKrst8XaS9SJZbObmTfEqFT5ACNd hF/GBOV3B6vHek91+r9zN2FeM5vEwq8JtMrl1cACixHqHDXfwyHWDpi1MNdvYsoZaN 3ERVeQqyCJU2b8enFyIUANNIn3/uxiZOexjEvZnrWGLv/AN6C0uxXNVvQMIZndFTHt gyFHNMrwQJwuJ5vLDAt/qtVHmrgN7iHbmgmhxKZSYs6j0L3WhXgt6IXAxmJBsBFqTy YLZW65thv7qRF5wnLxC8SIGENMbFCBWplqYXp+v/NcNx60DkpzzFQuYCgepmtIeicv rNaG+Vl7jKRdg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 57E3D180083 for ; Wed, 24 Apr 2024 08:23:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,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=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 24 Apr 2024 08:23:40 +0000 (UTC) Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a587fac79e5so192564166b.3 for ; Wed, 24 Apr 2024 01:23:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713946979; x=1714551779; darn=lists.php.net; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=7n60uXcJZCaX+gu/N1n/9UGLU3MHWN6aXBMBnVF0zpI=; b=l51lITSFRRaunyR2qCZHo+OyXjEZVT+7wP4BrL3RewjLH3ns2Gb20eg7s/VhiDh6uL JSopV3wzix9jfIi1XwcUtM+YBSXHzua1otEU/AJ6W4g685yn592GAB/gXwScBIUhya7B yFDNU5cZ7DkRZ38ZWE6lOPn6lHHOk8YfE32oQYW7VElY8SMhVRwWE40t0SXretPawP58 PGH7gfeP/RX7x2zIzrUpsTSRHwjMxB5smqujkdfA168tu/pGHz1CYMhCbBPfZOl6ASKJ HYL6kmmDjCNZdVPukMb6F7V7dy195gcykxF1S3tJn4/dKWYw2ICQlFhJvLcjeD/CrqA2 G9yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713946979; x=1714551779; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7n60uXcJZCaX+gu/N1n/9UGLU3MHWN6aXBMBnVF0zpI=; b=rBpJyP66RjV/BIaWSRWw7b4sNUDKO9MMubYisq9MSBB+t3RIww8tR6+3gb/e+5/jGt imX1SNEXF2nNc9rSC/UTxmkJ7B82+CMzV9/9zUMjm/NDWe1XvvdwPARMdR4EcjWeYULE QwBLMjR++2HGfXFUxmdbmKL8zVGzCsX1xVHWY0T3gHWBwEP2BgOUoO1IhXEZZJgYnEF9 ugmtqmw1lYztrzU3rGhwMAPpIJGIWCqGBc8Ef5jtmRWc2dbZI468q5Ny5H2bU9stV6sT k/AbD5nMzTlmJE/7ap24ErTLQ+cOoSFzMDXLoFl0eFJtsX7Jcb6rxxf6vJDBpQFEyZbL LMWA== X-Gm-Message-State: AOJu0YwdU/1g7+OzjgU72BgvqrzeIoFH8Yiyuz8TLydKIfCseo6F/GrW JcZzSzBytLDWYzGG94N4mYxYZmoSBOVuFhuTuA7bQ8SCQA8CT9y0eA7bAw== X-Google-Smtp-Source: AGHT+IHmp0iWd4Vq0nHZoWmmSL1Luaao2nOjgzUVrfuxmUCDD3V1B5PPxm71cThxT5Hk3mwIom1X1w== X-Received: by 2002:a17:906:6bcc:b0:a58:725b:a021 with SMTP id t12-20020a1709066bcc00b00a58725ba021mr998552ejs.15.1713946978922; Wed, 24 Apr 2024 01:22:58 -0700 (PDT) Received: from smtpclient.apple ([89.249.45.14]) by smtp.gmail.com with ESMTPSA id a7-20020a170906670700b00a522bef9f06sm8010947ejp.181.2024.04.24.01.22.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2024 01:22:58 -0700 (PDT) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_D5B0441D-AFC4-4189-82F6-0F29E29403D9" Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.500.171.1.1\)) Subject: Re: [PHP-DEV] [RFC] [Discussion] Add openStream() to XML{Reader,Writer} Date: Wed, 24 Apr 2024 10:22:47 +0200 In-Reply-To: <1deaa188-3b2c-4527-b3c3-fd5df1ee1757@gmail.com> Cc: internals@lists.php.net To: Niels Dossche References: <056a0e77-688e-40a9-86de-0bf71548c933@app.fastmail.com> <1deaa188-3b2c-4527-b3c3-fd5df1ee1757@gmail.com> X-Mailer: Apple Mail (2.3774.500.171.1.1) From: claude.pache@gmail.com (Claude Pache) --Apple-Mail=_D5B0441D-AFC4-4189-82F6-0F29E29403D9 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > Le 23 avr. 2024 =C3=A0 21:23, Niels Dossche = a =C3=A9crit : >=20 > On 22/04/2024 21:53, Larry Garfield wrote: >> On Mon, Apr 22, 2024, at 6:41 PM, Niels Dossche wrote: >>> Hi internals >>>=20 >>> I'm opening the discussion for my RFC "Add openStream() to = XML{Reader,Writer}". >>> RFC link: https://wiki.php.net/rfc/xmlreader_writer_streams >>>=20 >>> Kind regards >>> Niels >>=20 >> This seems quite reasonable to me overall. My one question is = regarding the writer version. Why is that not a static method, too? I = would have expected that to be a "named constructor" just like the = reader. >>=20 >> --Larry Garfield >=20 > Hi Larry >=20 > XMLReader already had these static methods that act as named = constructors, but XMLWriter has no named constructors at the moment. > The XMLWriter::openMemory() and XMLWriter::openUri() functions are = instance methods that must be called after doing "new XMLWriter". > If these two existing functions were static methods instead, I = would've made XMLWriter::openStream() static too. > So IOW, for consistency I followed the model of the existing XMLWriter = methods. >=20 > While it is possible to do the magic trick that XMLReader uses to have = the open methods on XMLWriter both static and non-static, this is quite = hacky and was only done to XMLReader for BC reasons. That=E2=80=99s odd. The inconsistency was introduced (or at least = sanctioned) in PHP 8.0. In PHP 7, XMLReader::open() and XMLReader::XML() = already worked when used both as static and non-static methods, but = triggered a deprecation warning when called statically. The deprecation = warning was removed in 8.0, regardless of the differing semantics when = called statically and non-statically, and regardless of the the = inconsistency with corresponding XMLWriter methods. Another point: when called statically on a subclass, both = `XMLReader::open()` and `XMLReader::XML()` return an object of type = `XMLReader`, not of the subclass: https://3v4l.org/lCOAvJ For that reason, they are unusable as static methods on a subclass. The = new `openStream()` method should work on instances, so that it will be = usable on subclasses. (And for the same reason, I think it was a mistake = to undeprecate `XMLReader::{open,XML}()` as static methods in 8.0.) =E2=80=94Claude --Apple-Mail=_D5B0441D-AFC4-4189-82F6-0F29E29403D9 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

Le 23 avr. 2024 =C3=A0 21:23, Niels Dossche = <dossche.niels@gmail.com> a =C3=A9crit :

On 22/04/2024 21:53, Larry = Garfield wrote:
On Mon, Apr 22, 2024, at = 6:41 PM, Niels Dossche wrote:
Hi = internals

I'm opening the discussion for my RFC "Add openStream() = to XML{Reader,Writer}".
RFC link: = https://wiki.php.net/rfc/xmlreader_writer_streams

Kind = regards
Niels

This seems quite reasonable to me = overall.  My one question is regarding the writer version. =  Why is that not a static method, too?  I would have expected = that to be a "named constructor" just like the reader.

--Larry = Garfield

Hi Larry

XMLReader already had these = static methods that act as named constructors, but XMLWriter has no = named constructors at the moment.
The XMLWriter::openMemory() and = XMLWriter::openUri() functions are instance methods that must be called = after doing "new XMLWriter".
If these two existing functions were = static methods instead, I would've made XMLWriter::openStream() static = too.
So IOW, for consistency I followed the model of the existing = XMLWriter methods.

While it is possible to do the magic trick = that XMLReader uses to have the open methods on XMLWriter both static = and non-static, this is quite hacky and was only done to XMLReader for = BC reasons.

That=E2=80=99s = odd. The inconsistency was introduced (or at least sanctioned) in PHP = 8.0. In PHP 7, XMLReader::open() and XMLReader::XML() already worked = when used both as static and non-static methods, but triggered a = deprecation warning when called statically. The deprecation warning was = removed in 8.0, regardless of the differing semantics when called = statically and non-statically, and regardless of the the inconsistency = with corresponding XMLWriter methods.

Another = point: when called statically on a subclass, both `XMLReader::open()` = and `XMLReader::XML()` return an object of type `XMLReader`, not of the = subclass: https://3v4l.org/lCOAvJ
For= that reason, they are unusable as static methods on a subclass. The new = `openStream()` method should work on instances, so that it will be = usable on subclasses. (And for the same reason, I think it was a mistake = to undeprecate `XMLReader::{open,XML}()` as static methods in = 8.0.)

=E2=80=94Claude

= = --Apple-Mail=_D5B0441D-AFC4-4189-82F6-0F29E29403D9--