Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110914 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 48798 invoked from network); 10 Jul 2020 11:32:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 Jul 2020 11:32:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5A27218050B for ; Fri, 10 Jul 2020 03:24:21 -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-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 ; Fri, 10 Jul 2020 03:24:20 -0700 (PDT) Received: by mail-il1-f173.google.com with SMTP id o3so4591357ilo.12 for ; Fri, 10 Jul 2020 03:24:20 -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 :cc; bh=Cqd4iBIi6Q1MqO9Y8l1EukbYHn7HqghUzb01b4bh4qI=; b=nxNs0uMIWsfYRDz/A5gTEnfSIJH1i1JzRkEVzzTyztroponrQDE4+4gkoja1lIB2Cc ml32uHxvo8G1XFV5FX0VocfepIj+O7KMYo8ddc/n0dDzt3lBGu65685vExfgyVevmppB G68QXfkMWUno3LgVNYGagqYfw/sH+0GLQo0jGBHdXOGZU++tOzugPFOw5xSu6ECEyKUI 161tMpsW+ejmEiM1hVKXVqp1hhkVI5/ePomiOZNT4k7Y4209zrgMp0mCqjpffhNvtMFU GuNV1uZqS62RpW+FFvGn0NMMeEkERhRNYMip/xzdo7c8k7NajKj2gAoHIVMIGcgSFqIx jLZQ== 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:cc; bh=Cqd4iBIi6Q1MqO9Y8l1EukbYHn7HqghUzb01b4bh4qI=; b=sYMUj4H7GTm0dsjImSfvKrhMqFe1EzzlW2t5wDDcAP1juVkJStQ2VHCZri9EGLdW3p jOChz4TQpAWfjTtGtCmER6UPyrqODsF52hSUjMOEx1tm6FM46ZzrLNmoCLglcC6NgPxZ f711HiMOzY2rmmu7M/y5Sk0XkLl8D6hStfvG+gElCT1mxQpbuJ2JtupXT6lO/YU1le+P pYBE5ZkqHxwfh/ESI4y5uPLHFm3yg0wunCID2ljp6hqNUZ4MdwZ5SX8bVEX5AkkY4axz SliPslMUOYu55uKkaeCj1ij/mAYjk4hY4iheeHr6l9dNC7uV0IVp0xNQnqT7eVOf4nRg kc1w== X-Gm-Message-State: AOAM530DEo/gFESkg2zFFLILLBb5jBRX6wODbr5rAPkytML1Q4P/F3T6 k97f6hg4KKAXM44YUFwTrTKPrBDONLYQ4PWztYQ= X-Google-Smtp-Source: ABdhPJyJV6yUBFkL3QtlE0jq+UhKWrCGjOesgOnXoG0hOFlxdibfcFPV4Co/av2c/jAx1WcMVJNeKwZaRFEWcsvioes= X-Received: by 2002:a92:cd04:: with SMTP id z4mr51738496iln.165.1594376660155; Fri, 10 Jul 2020 03:24:20 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 10 Jul 2020 12:24:08 +0200 Message-ID: To: Rowan Tommins Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000077843705aa13be0b" Subject: Re: [PHP-DEV] [VOTE] Named arguments From: ocramius@gmail.com (Marco Pivetta) --00000000000077843705aa13be0b Content-Type: text/plain; charset="UTF-8" Hey Rowan, On Fri, Jul 10, 2020 at 12:11 PM Rowan Tommins wrote: > On Fri, 10 Jul 2020 at 10:21, Marco Pivetta wrote: > > > I kept my "NO" stance here, as per discussion in > > https://externals.io/message/110004#110005, where I provided (in my > > opinion) good/safe alternatives to arrays as input parameters. > > > > > For the record, I maintain my reaction from > https://externals.io/message/110004#110010 that the example you give > "cheats" by including a "fromArray" method which simply emulates named > parameters, but without any assistance from the language would require a > large amount of boiler-plate to do so. > If "array" is all you have to pass on as input, `fromArray` is what you can certainly use: that's useful when de-serializing from JSON input, DB, serialized state, etc. It certainly isn't meant to pass in the array via hand-crafted map: that's what other (additional) named ctors would be for. > Would you be more open to a version of the feature that was opt-in at the > definition site? Most certainly: as mentioned elsewhere (can't find it), having an attribute to demarcate whether an API can be used via named arguments would make the BC surface and BC promise explicit and clear. > Then your example could swap the hand-rolled documentation > and validation in "fromArray" for a fully typed signature in > "fromNamedParams", and the only compatibility promises would be ones > already made by "fromArray" anyway. The idea of multiple named ctors is to keep BC compatibility whilst allowing for multiple input formats that fit the current use-case. Data format changes? New ctor! Not a problem, unless internal invariants change massively. For example, in event-sourcing, you can likely never update past data (never, really!), so as you move forward, your de-serialization endpoints may be appropriately versioned: a `MyEvent::fromSerializedData(array)` must be designed to support all possible past representations of `MyEvent` (even if no longer complying with current domain rules), whereas `MyEvent::fromInput(PSR7Request)` can actively refuse invalid information (context matters a lot). ```php MyEvent::fromArray([ 'hand' => 'crafted', 'set' => 'of', 'parameters' => 'is', 'certainly' => 'not', 'how' => 'this', 'is' => supposed', 'to' => 'be', 'used', 'and' => 'causes', 'only' => 'trouble' ]); ``` The above is just complexity, and a lot of moving parts to keep track of. When coding with a defined data-set, you use `MyEvent::raise($with, $relevant, $typed, $information, $only);` I feel like I'm repeating myself though: this was already explained before. Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ --00000000000077843705aa13be0b--