Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110010 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 37481 invoked from network); 5 May 2020 17:53:07 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 May 2020 17:53:07 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 245FC1804C9 for ; Tue, 5 May 2020 09:28:05 -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,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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-il1-f173.google.com (mail-il1-f173.google.com [209.85.166.173]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 5 May 2020 09:28:04 -0700 (PDT) Received: by mail-il1-f173.google.com with SMTP id x2so1592973ilp.13 for ; Tue, 05 May 2020 09:28:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=u0mVYE6Ijf6T4hF2vWWrvv2K/UAFsU8HXa2Jdau8Yk4=; b=oIujjdcZ+/Yj78Z9DEVgzcxMxC5eEfT0m2eMBjWJysKEXKhAKwVWOA31JTDHgawBe/ Y3171pmHSmU+LcKteP4ICOWQswaR5/SuWbjrg6RISqxpq2CGMNsZgDBb+CjdZSSw0/aG NrZmSjpvW4I6C1wtOMWueI/Y4bPY6uHl0DWVc8Q1ingS6Z1m7Ez8cq/cEJKzJAPIYhgN C8vYIqP1SWL1o1fMTFDXc1gt8mwXZ8oWv2uxFloUOFgNJGfDisM+Id1k8ZkjwOtt8lhv +54t610Mz/LK9tujPQac+C4nnCy+D2lJahgsWLsK0flhX/Liz1ofqatNU6pkf3ZD3Ayf UB7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=u0mVYE6Ijf6T4hF2vWWrvv2K/UAFsU8HXa2Jdau8Yk4=; b=aHozUqpJImvOQZrNinc9SGV6uBrF0uoRZ2PRWg7CESKMvqwdxT9cw6a+VTDBTv8y15 RZSGe++Zc87lhjg2a9WdqA/bDbjxIKpqul3R3I2K8dzQXhAAlygiMqQpwlxTnjTHFJY7 zxuBGYKzwY3ZKe2swSYQ3UlWCNaO4I8W5v8qU4YaPN1LjqfinEg8+KGeIfyjalVCzT2q r/bzAJDD9XDnRLvtzPPoOCyEL0pMYapGhgBeirX4qUFMHJjqurUTHIXcwQ5bcYze0vhC IPbGgTBGqLdX32PYgT12u4P0o+MIlP2bN/tqrz2h7t/WFZtXTN5OyrlXsCH5zm8d+a9D y+sQ== X-Gm-Message-State: AGi0PuZqwyMHzi6g9s8zEAu5Ff4JiVdxOIW7t1Gh7X6XUChmhPKJTpMW gwK1+0hDx2ObCGcuJ3IAhOLtdlzasQHyk6ENfWVWX/8W X-Google-Smtp-Source: APiQypJy1oDNEOGUKQlrN9VfNMc+p6kALcuIcCAgGaHpmg/BvCC9lW9h3wUmk0LH/De0GHEti6JVv+Aio09KBh2LNQ8= X-Received: by 2002:a05:6e02:5cb:: with SMTP id l11mr4567405ils.236.1588696083983; Tue, 05 May 2020 09:28:03 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 5 May 2020 17:27:52 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="000000000000bdf2b005a4e92118" Subject: Re: [PHP-DEV] [RFC] Named arguments From: rowan.collins@gmail.com (Rowan Tommins) --000000000000bdf2b005a4e92118 Content-Type: text/plain; charset="UTF-8" On Tue, 5 May 2020 at 16:56, Marco Pivetta wrote: > > Sorry, but no: you provide multiple constructors, each with a limited set > of arguments, each guaranteeing constraints that depend on context. > > For instance, a `fromArray()` may check for key existence, while > `fromJson()` may use a JSON-Schema definition to check that all is as > required, and `fromXmlPayload()` may apply an XSD validator, and so on... > Maybe it's just an unfortunate choice of example, but my reaction was the same as Benjamin's: "fromArray" doesn't look like "a named constructor with a limited set of arguments", it looks like a hack used to emulate named parameters by setting them as keys in an array which then has to be manually documented and validated. The only fully generic alternative I know of that can be properly checked by static analysis is some kind of builder API: myHorribleLegacyAndOrganicallyGrownApi( ...(new MyInfiniteSequenceOfParametersBuilder) ->setFoo($foo) ->setBar($bar) // ... etc ->toSequentialParameters() ); I do sympathise with the problems of making parameter names part of the compatibility contract, and until recently have always argued it should be opt-in at the call-site. I've been somewhat won round to the idea that that leaves the migration too painfully slow. Regards, -- Rowan Tommins [IMSoP] --000000000000bdf2b005a4e92118--