Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123204 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 6C6711A009C for ; Wed, 24 Apr 2024 19:29:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1713986981; bh=z2x9VUAWgrWo2ssNaI3svMmWO6YmYe0NBkUPK4FLyLw=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=YWc4e0n2ST62LE03EHkVpV2YpP0bFPRM8rV9qlFdVVoQ+ZjBAduADb83r8WGkX1kt 9AundPNmLuGxxpF/XQyq2oSe3kzlRR4oCoXvRMsFlQY2DMC0hmie7FTQYwFyWHouYB pQ6045JAWjhXu2UhWLA3enOGaMnQKauJ9aalFpKpUwPbV0rtUkPUeljZ/qxgNjomxj eTdFSMRqxJYED7+klG3h+IrN1hhHP73LJcgj2VhHZ+hKru9vaXVgX2eQNETcXu34bK xCgHloR8bbuIK1BxkFb2O2MmLU5Je+H/kvGuwJGEe5bt8LQsozGn6G9pCEZs8HjMQM 9OehT+y7rKAhQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 76BA0180004 for ; Wed, 24 Apr 2024 19:29:40 +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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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-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 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 19:29:40 +0000 (UTC) Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-34b66f0500aso134316f8f.3 for ; Wed, 24 Apr 2024 12:28:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713986938; x=1714591738; 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=202RyKAQldqpGV1henarO27qfJ7rGEC0lsnwYmK0ouI=; b=IhezO3NadawmNcrRsm2OdMV87N5Rozc9X5Ne1o/Xn7AjanIlgjUV+atrz1fU54blTX k+c1aJ0MsN/o5J5jLEgQeM3EOevwjM0SXaaYhq8ONM6oiZOxN//lOClhQL9SVh+8Hj8V apWmgAyskpCO80sVLLiVUeeNzTEQaSxDAzjk2YWYUyJ+zADRAjh8p4mladmsiNVXSFDV ge5EfeioMY4nDhb/ayj7QzJfliwO6GtoDaYEjMJnmOlfZgZu2LVT0r2TOF70kgFFHiow RNQRf30+Xi/g3hOMnDHzZu+HXzu+MW7P/SZUeGlYdulmExKZNY9JmoGlKKO7E+eyVFsl qG5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713986938; x=1714591738; 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=202RyKAQldqpGV1henarO27qfJ7rGEC0lsnwYmK0ouI=; b=W+ZluU3ZVbLPpI+j8hVYZQQlioGZ1pwULXx40vCtJYaAm948MjTt2K51VwH9fzd/EE O19qudaKUuZdC3vYT9P3pg5BlPfkSKEyxCcWruJTAXM2vtNdCubs8sYXauPbFjhjg8J/ LjMpC4ikBihPEF1lOf/SHLM6McDgT2d5ISLSOyHy2xqNR06qVnbBWe0UxFEropw42uee XOoJcDPukIkeyCb9AnGnoBHr04fo5hKbA4gwkMrnM+4Vp71mQKJD2K+wVOT5Qx/fDeL2 OaGSdFAAx09gX9B3G+MIbicyMOci0Qj7ieTB9bcwvAYEjc2psrGVi8UmN91MoK/GMpQV Z5Fg== X-Gm-Message-State: AOJu0YxRVd4WHHPW9aIQBBaTUAI/DwTEXYQ2B/g7m0lgRc2Lahj2I//t J9f2gRPcGH9UukrVgqsNeRg91z+oTqELiu8vnRsX4iyVYc8pZtPP X-Google-Smtp-Source: AGHT+IH9cqv3NcXayfGVLjRXydQTK8tJtl9q8xzO5GFk3eQTPmcyrlAlVVwOV2WKW3jrkhXezvzg4A== X-Received: by 2002:a5d:6392:0:b0:347:1c20:f262 with SMTP id p18-20020a5d6392000000b003471c20f262mr2273825wru.16.1713986937951; Wed, 24 Apr 2024 12:28:57 -0700 (PDT) Received: from [192.168.0.102] (178-117-134-240.access.telenet.be. [178.117.134.240]) by smtp.gmail.com with ESMTPSA id cs18-20020a056000089200b003437799a373sm18021977wrb.83.2024.04.24.12.28.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 Apr 2024 12:28:57 -0700 (PDT) Message-ID: <4ff881d0-6f1c-43aa-84a0-f91dab8c9a50@gmail.com> Date: Wed, 24 Apr 2024 21:27:04 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC] [Discussion] Add openStream() to XML{Reader,Writer} To: Claude Pache Cc: internals@lists.php.net References: <056a0e77-688e-40a9-86de-0bf71548c933@app.fastmail.com> <1deaa188-3b2c-4527-b3c3-fd5df1ee1757@gmail.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: dossche.niels@gmail.com (Niels Dossche) On 24/04/2024 10:22, Claude Pache wrote: > > >> Le 23 avr. 2024 à 21:23, Niels Dossche a écrit : >> >> 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’s 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.) This is a good point indeed, good catch! I agree it should be an instance method then to avoid this problem. It also makes me wonder why the static form is the canonical form shown in the manual (https://www.php.net/manual/en/xmlreader.open)... We should probably show the instance method as the recommended one. I also checked whether it's possible to return "static" instead of "XMLReader" for the existing static functions, but that's not possible in the general case because we won't know with which arguments to call the constructor... Anyway, I'm going to update the RFC for this. > > —Claude > Kind regards Niels