Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91223 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66997 invoked from network); 12 Feb 2016 15:13:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Feb 2016 15:13:39 -0000 Authentication-Results: pb1.pair.com smtp.mail=ua.san.alex@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ua.san.alex@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.169 as permitted sender) X-PHP-List-Original-Sender: ua.san.alex@gmail.com X-Host-Fingerprint: 209.85.223.169 mail-io0-f169.google.com Received: from [209.85.223.169] ([209.85.223.169:33616] helo=mail-io0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E5/00-00989-1A6FDB65 for ; Fri, 12 Feb 2016 10:13:37 -0500 Received: by mail-io0-f169.google.com with SMTP id z135so24932636iof.0 for ; Fri, 12 Feb 2016 07:13:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=oIQrAoaybgI7bQMDnFLq44Brwqd3o1nntkxiPBu4Ub8=; b=ASchkm7E1TSrhlGu5bm/T6EQQJ0yUuhdE8CTm5TBX4JTO9bzwcFx1w/O56Dc/Nc6kU kldIyLLiKyScDKlmXTYInKjic4wRmFuQv+PIB4v/o5RJIgFc33Griv2YQErDjPG4DMwC b/CJRXW++DfXW169PVDqf3EesIMsUToDVyaIthq9+061jih4RLgYdoych1xDjRyKTpNz Jm+5HV1p7w9vJUuLaE9cVizFTJ4E8gjCtvQ/PmWGyDL8X3KKHMbKiAZicib3SqPdjFfC oA9MpcApT74Eaz+0iDlDCanMBYp9/ZVdUbSzHqhdJ6P1VIJZEt1eAVy9ie1y7AxDNe8V US2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=oIQrAoaybgI7bQMDnFLq44Brwqd3o1nntkxiPBu4Ub8=; b=Ih4F1FexYMhnAeYnas80OyTki9mfQWkBu78vLcHouL/cQlOyTLf/cwHa/OkNfPFCO1 y5zkvoz8mXP58pPvqpmwdd5BCsyg1r2YiLVU4OkKP31BmdQwi4fgjhKDzsy3mVPxNnUG tQnYrvCKPaVVNQEnY5NeeGmpg+nl2fP1PI604KJ+QD7EltCgZ34UvzKSouqntHKQrNY3 80g1ls0rx5rZoZ/NaiwNy/pFDGrZDmH6qPbJ/P+3f8Kjao3NMgzkd+kT1gD/PRBEkmvq /J1cyLP6LKYQx/iFdwKzLzAi834aSKl8MXZ8kTWxpPz5R7cpcSwholEDbBtKNhGIc/lw Dgxg== X-Gm-Message-State: AG10YOSJ68kMVP3BFP8u9UZJ+UVZoFpNWrKkMhcB0h+bNbO66sM/QQAC0t65HoWx0hdMs56pgiZIHb2o1LHZ4Q== MIME-Version: 1.0 X-Received: by 10.107.17.24 with SMTP id z24mr3111334ioi.78.1455290014691; Fri, 12 Feb 2016 07:13:34 -0800 (PST) Received: by 10.50.31.169 with HTTP; Fri, 12 Feb 2016 07:13:34 -0800 (PST) In-Reply-To: <56BDF26B.8030301@gmail.com> References: <38.31.07203.2EB94B65@pb1.pair.com> <8E.1A.36326.338F8B65@pb1.pair.com> <56BDEBC8.4090806@gmail.com> <56BDF26B.8030301@gmail.com> Date: Fri, 12 Feb 2016 17:13:34 +0200 Message-ID: To: Rowan Collins Cc: internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC][VOTE] Allow specifying keys in list() From: ua.san.alex@gmail.com ("S.A.N") 2016-02-12 16:55 GMT+02:00 Rowan Collins : > S.A.N wrote on 12/02/2016 14:39: >> >> 2016-02-12 16:27 GMT+02:00 Rowan Collins : >>> >>> S.A.N wrote on 12/02/2016 13:37: >>>> >>>> Often all keys are unknown, or a very lot keys, use list(...) - is >>>> unreal. >>>> >>>> I would like to, instead >>> >>>> foreach($params as $key => $value) >>>> { >>>> $this{$key} = $value >>>> } >>>> >>>> Use the short syntax sugar >>> >>>> $this += $params >>>> >>>> ?> >>>> >>>> It's really do? >>>> >>> If the keys are unknown, then you probably don't want to blindly copy >>> them >>> onto object properties; at that point, you might as well just have >>> $this->data and leave them as an array. It sounds like what you actually >>> want is an object literal syntax - i.e. $params should never have been an >>> array in the first place. >>> >> I would operator (+=) as like to function Object.assign() >> >> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign > > > Sure, but I was thinking more in terms of whether this is a strong use case > for having it. In JS, "Object" is the appropriate type for an arbitrary hash > of key-value pairs. In PHP, the appropriate type for such a structure is > "array", which already supports the + operator and array_merge function. > > Note that the method you linked doesn't copy from an array onto an object, > it copies from one object to another. Doing the same in PHP leaves the > question of how you create the right-hand object, which is why I mentioned > "object literal syntax", i.e. the ability to write something like "{ a => > 42, b => 'Hello' }" or "new Foo { a => 42, b => 'Hello' }" to define an > object with directly-specified property values, rather than running the > constructor. > > The constructor example using list() syntax is deliberately naming the > fields we're interested in, because it's populating an object of a > particular class, with known property names, not dynamically creating > arbitrary property keys. > > Regards, > -- > Rowan Collins > [IMSoP] > I agree, list() syntax and object literal syntax - is need, +1 But is also necessary and the function or operator like object_assign($target, ...$sources)