Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109089 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 89643 invoked from network); 17 Mar 2020 03:24:44 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Mar 2020 03:24:44 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D24271804E6 for ; Mon, 16 Mar 2020 18:47:17 -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=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, 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-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 ; Mon, 16 Mar 2020 18:47:17 -0700 (PDT) Received: by mail-lj1-f182.google.com with SMTP id o10so20940327ljc.8 for ; Mon, 16 Mar 2020 18:47:17 -0700 (PDT) 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=7QjoAzc/pkjzvFSIT8uUCgejIFRePLF8IeSdTg6I00k=; b=Mms/KwI7gYuho/6HwVdevLqGFeEn+nsWQmNUuD3H6K60mGrQfgAWv2o9KOWP15YOnF NkdPvTtisR92loJ4Qr2UPeJ5bK4fDPl+akiW9VjXiwXQAQMsfc7v0Ur0IgcP7NJRhtbF ITSl3fv/WJH/VbwBh2+3rnQ3vRvHJQMNMn77vwD9Bs5lNi4UpuNU+wuQQp1NBvi+FzH6 sxInD+7xhmsjPi5sgSPSPRqMNCd9uCb7FgELu7OZAYNbkvG9Zddjv2VTcQCfQF7dtIcF oQkKVLKlsaNAkslOE0tQiY/gWYNvjUzhiLJC0Sg0qoQcPO2rrQO1319iwvx9SU4O/S/f PWhw== X-Gm-Message-State: ANhLgQ1jru3jHI9WBG2WVlpJUxP7jx1K/ueYJIvybDAnKeWpHv7iOQb+ hlN+deDDaSzPpWKBwbUWyVOdYiiRV4AWYECF6hM= X-Google-Smtp-Source: ADFU+vv02TIC/gwfrGJeGk19XtEFKPfMEmzxrXfAkGda6frM5SKy6wdU3kQFq8UKLEXgBFBuGo9eqlVaNt59CCvJlVg= X-Received: by 2002:a05:651c:106:: with SMTP id a6mr1245079ljb.143.1584409635945; Mon, 16 Mar 2020 18:47:15 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 16 Mar 2020 20:47:04 -0500 Message-ID: To: Rowan Tommins Cc: php internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] [DISCUSSION] Compact Object Property Assignment From: jakob@givoni.dk (Jakob Givoni) On Mon, Mar 16, 2020 at 10:40 AM Rowan Tommins wrote: > Thanks for having another go at this feature, which I think a lot of people > would like in some form. I agree! > Maybe we want to have all four, but that would leave us with a lot of > different ways of initialising objects, which might not be such a good > thing. Remember that the RFC explicitly says it's not an object initializer, nor does it solve "named parameters" which you mention. If I had the choice, I'd go with named parameters when creating an object, but I don't and this is the next best thing. It's simple and it doesn't introduce any new concepts. It just allows you to do something inline that you could until now only do line by line. > You mention using "argument bag" objects in place of named parameters, but > that feels like it would be even more awkward than using an associative > array. The associative array is a common pattern, but it defeats name and type checking. An Options class add almost no extra boilerplate since you simply move the properties from the main class to the Options class. Notice that in contrary to your example, I simply copy the Options object whole into the main class. > COPA can only validate individual > parameters, not the whole object; so it's hard to complain if the user > forgets a mandatory field Correct, the goals for COPA are quite clear in the "Motivation" section and that kind of validation is not one of them Luckily you can still do things the way you prefer without COPA if it doesn't suit you :-) Best, Jakob