Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126081 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 1B2E41A00BD for ; Fri, 29 Nov 2024 12:28:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1732883113; bh=P1IZ+FVImBd8xlpzwjd0y6R6bcAJJ1HTCPMBpYWeY40=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=UIQoZVP83dZ59Uq0BYzlCaB63i4mm0voZfWcU3h1vwEoynuCk5FzIANwXS0Y0Mf01 LmQvCPpJZasHsjbn1Un5ZvD9nFaw2TkeAfwcOZcrY8XsdZzFFROn4wicpVDDDtMvh9 Do1Q/0uZTRcvseEgSfHFw8J2p4+rNAiA+pXLSLIWOe3A0FPFcxWNtzgd4dRcMYlRk1 1j1ClNe40e4lkx2+DhLW3ttzSNNcC5ltdp/wPgoTg7bPDc8WlEl/FKEmIdAbH2uBRm xkG0OpOkVW71X19VTkT6bEHqLjCBWtN3+yCcEpYpoq/IKLAbTmB13hnrF8nWBTFvwU HFwQd2vDaPBjQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8F5E7180062 for ; Fri, 29 Nov 2024 12:25:12 +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,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (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 ; Fri, 29 Nov 2024 12:25:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1732883300; bh=HNHfkZaEhoDGFman6hU/Rsza5T9OI99fJ1LlE2LtRRU=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=O5ivt0extS1uys7VF+mIqMvm/2Q67+8+K2O4U0ug4nerWAo8BVZDbd4B15op9bMkG VlMQIiehhMuMDuSLk4+zdiY/0I34nCqH3ZmH6KkHCZKZfl+hDo2M0ZcRxetRl3NnnT JdW4VKb6OLhjNud0eb44UdsJvhG1j9XkoltwNrjRTX4qkJZXPK6McY5F5Gg3IXrg+r F+NSj+IfZNl7LrvYq3w1VE9OJEKr2bae9xaWjpL6UmOHzwCIijUmM032nt25cLep/u EHikdOHS6FNZzl7BiauqibnVQwzo6wqD2AI1RAsM9vu9phyHuo0ZyEcEFGkwJ/E8D6 e4Nb5i0Qvesow== Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Fri, 29 Nov 2024 13:28:20 +0100 To: =?UTF-8?Q?M=C3=A1t=C3=A9_Kocsis?= Cc: Larry Garfield , php internals Subject: Re: [PHP-DEV] [RFC] [Discussion] Add WHATWG compliant URL parsing API In-Reply-To: References: Message-ID: <66cdd51cc77ce4be73801c4f0735f440@bastelstu.be> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi Am 2024-11-24 21:40, schrieb Máté Kocsis: >> It took me a while to realize that, I think, the fromWhatWg() method >> is >> using an in/out parameter for error handling. That is an insta-no on >> my >> part. in/out reference parameters make sense in C, maybe C++, and >> basically nowhere else. I view them as a code smell everywhere >> they're >> used in PHP. Better alternatives include exceptions or union returns. >> > > Yes, originally the RFC used a reference parameter to return the error > during parsing. I knew it was controversial, but that's what was a > consistent choice with other internal functions/methods. > After your feedback, I changed this behavior to an union type return > type: > > public static function parse(string $uri, ?string $baseUrl = null): > static|array {} > > So that in case of failure, an array of Uri\WhatWgError objects are > returned. This practice is not really idiomatic with PHP, so personally > I'm > not sure I like it, but neither did I particularly like passing a > parameter > by reference... I disagree with this change and believe that with the current capabilities of PHP the out-parameter is the correct API design choice, because then the “failure” case would be returning a falsy value, which IMO is pretty idiomatic PHP: if (($uri = WhatWgUri::parse($someUri, errors: $errors)) !== null) { printf("Your URI '%s' is valid. Here it is: %s", $someUri, $uri); } else { printf("Your URI '%s' is invalid, there were %d errors.\n", $someUri, $errors); } It would also unify the API between Rfc3986Uri and WhatWgUri. Best regards Tim Düsterhus