Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109083 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 78167 invoked from network); 17 Mar 2020 02:51:10 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Mar 2020 02:51:10 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 915C21804E0 for ; Mon, 16 Mar 2020 18:13:42 -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-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (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:13:41 -0700 (PDT) Received: by mail-lj1-f181.google.com with SMTP id s13so20900859ljm.1 for ; Mon, 16 Mar 2020 18:13:41 -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:content-transfer-encoding; bh=TAdo3vJyK87psnis/MH/p32wHsfapunV8ek8zq2itE4=; b=fBB9ZtHLAtX8AH+ugH4edD4KK1rv7lFfKy0/ZYdvpnb030CmHJt+C2WWBMeSUzXXfg ydGGuw0mCMJkV+Ru+Gym90qfB1JdQCbVOxyhCAXEueakH8xZ9sbFJ6YgZRjpx/c6urqH fUSsV+Pn7Vj+jIxHQo5ilbnDB/hFSGVqJ2I5YIm1qyWy5VD4cGdBKjFW/6KT7PuHrV9f w//xCOJQX2fK2DOBxL/CHy+2kWDzcXqIz7RdRhgDTZ21EcUJLHPaiJs3bcJkH2VtASjM oy+/dK7jNrgqqmBQJoglp0zq4NnHLbPMbuZG8COipW155q1yZxISMP3YRQYYiLKJ8K1n VCCw== X-Gm-Message-State: ANhLgQ0tMZKI/On1ik/Q4uhwReunHf3Q3B3B4W+PTW8ghje2BI6Xwa8r d/opbjFcj7BHnM/sgRF6LPHRtMYaQ8w5Gh7s5kA= X-Google-Smtp-Source: ADFU+vt990GBYnRNkMux6BhDRl288GkZOuqnnRId91gH2q1S6pdkm3t4BZQ7uVfwupD+6mVZZTpvpsfBjUKC9y+wy+U= X-Received: by 2002:a2e:97cf:: with SMTP id m15mr1110760ljj.30.1584407618100; Mon, 16 Mar 2020 18:13:38 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 16 Mar 2020 20:13:27 -0500 Message-ID: To: Matthew Brown Cc: php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] [DISCUSSION] Compact Object Property Assignment From: jakob@givoni.dk (Jakob Givoni) On Mon, Mar 16, 2020 at 9:10 AM Matthew Brown wr= ote: > I love the idea! Thanks Matthew! > The syntax for new objects looks a little verbose =E2=80=93 would it be p= ossible to use > > $foo =3D new Foo()[ > property1 =3D "hello", > property2 =3D 5, > ]; The short answer: I don't think so. This is not possible (though it's arguably 'nicer'): new Foo()->doSomething(); // syntax error, unexpected '->' Not sure why, but it's necessary to wrap the instantiation in brackets: (new Foo())->doSomething(); // Ok If someone can explain why, it would be enlightening! Furthermore, dropping the arrow would create conflicting syntax with array access: $foo[1]; // Array access, give me the element with index 1, can be used on objects as well $foo[a =3D 1]; // Property assignment... ??? I'll update the RFC to reflect your proposal. Thank you, Jakob