Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91222 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64869 invoked from network); 12 Feb 2016 14:57:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Feb 2016 14:57:30 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.44 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.44 mail-wm0-f44.google.com Received: from [74.125.82.44] ([74.125.82.44:34596] helo=mail-wm0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C7/94-25203-9D2FDB65 for ; Fri, 12 Feb 2016 09:57:29 -0500 Received: by mail-wm0-f44.google.com with SMTP id 128so65566479wmz.1 for ; Fri, 12 Feb 2016 06:57:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:cc:message-id:date:user-agent :mime-version:in-reply-to:content-type:content-transfer-encoding; bh=tAADj9og3sMk7xwRURZkHdCUKLLwZFQJ4G4W4CM9XmE=; b=TlPWj04AD04tJdcB7erjB/vXdMiAPt8opQ1puimk/qYj6PE+G7eJShJnw7yij5ygJm XUHPqPhAxU5xy66Tveagq66hTnupBOEUh6ost7nCZE2hHoVZNJqwtlCQ0u/k1CS/iqkl 0eZ58oCzEfYhmp/5S+D4B8el31/zYhu30s7ylQ2AhWuL94u6DybQiNiVKWcmKQhzdGSw 8MVthR1bHnjg/dzQDNQnDwvTrXC8YOIORul8HhTG310a3X4JN7xMJn3fp///bVhJpwJ+ zM522rsYL3gedL+8hwwL3zyz1c6yEll7lqjGJQfOn5Ht5T7qlLSSZ1xA/F9MUblJ/K/e AMpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:cc:message-id:date :user-agent:mime-version:in-reply-to:content-type :content-transfer-encoding; bh=tAADj9og3sMk7xwRURZkHdCUKLLwZFQJ4G4W4CM9XmE=; b=cvhhGooaO58Kn5pcjqP0hOw2nmtqdzcwqAC8a2Z8WfqrJgoUDKcSJjDuocnDIll9mG afBSs2zX34bnyOMxQ9i+PQdft5q0nVuuyg1xIulha89qvUx2VUXN8f3uUCgD0BM0A0xI b2wT8kc/2gWw4aqwMASkJwLnvXlwt9rNktw8A5LzvxDOxqtrsZjRuViqAwxSTvQM8oXi XYG6TtO8pAP9tZpxE95prSlwH+G4XR5+7ISC1I0bNPAkuH8/P77irlaODR7jlsvfqtrn 3OA9W0f6msQ5V49y88FMKdJwenZ0Cfd/S4zzx0x3id/cnylDRWPJWUYJ8deOH2ZGrQOV FQ6g== X-Gm-Message-State: AG10YOTGcs42MCBS/QkFWy7jM/j4kYfqQDrTcyM9/5G1MARHXaIdDr7WFdYAZ/Fjxf8dBQ== X-Received: by 10.28.32.147 with SMTP id g141mr4829025wmg.19.1455289046782; Fri, 12 Feb 2016 06:57:26 -0800 (PST) Received: from [192.168.0.152] ([93.188.182.58]) by smtp.googlemail.com with ESMTPSA id ka4sm12403907wjc.47.2016.02.12.06.57.25 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 12 Feb 2016 06:57:25 -0800 (PST) To: internals References: <38.31.07203.2EB94B65@pb1.pair.com> <8E.1A.36326.338F8B65@pb1.pair.com> <56BDEBC8.4090806@gmail.com> Cc: "S.A.N" Message-ID: <56BDF26B.8030301@gmail.com> Date: Fri, 12 Feb 2016 14:55:39 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC][VOTE] Allow specifying keys in list() From: rowan.collins@gmail.com (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]