Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99329 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 2028 invoked from network); 2 Jun 2017 18:05:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Jun 2017 18:05:07 -0000 Authentication-Results: pb1.pair.com header.from=tendoaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tendoaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.182 as permitted sender) X-PHP-List-Original-Sender: tendoaki@gmail.com X-Host-Fingerprint: 209.85.217.182 mail-ua0-f182.google.com Received: from [209.85.217.182] ([209.85.217.182:34235] helo=mail-ua0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 14/E9-12681-2D8A1395 for ; Fri, 02 Jun 2017 14:05:07 -0400 Received: by mail-ua0-f182.google.com with SMTP id u10so49191041uaf.1 for ; Fri, 02 Jun 2017 11:05:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=Qm7wsKkc29j7D7uh+iJPFpU+0cHgvEtdvrqyGj2BgOU=; b=DBccTaLsU01CZ/0LD9GwXdx+LPNy88NQTiUsiQiXrW8bb9orYL7nPmC5jybVHnJT0T 9Mk+5ewW7jWKVcptgqHE+NF4bdMrX1/0vjLnPRgjZQvbd7rI+7+Vnlx70wzH6bOeBLnf gd/unZ5m9OrHNYkOuZHNbp2QylDyV0Iti7hZsaxA5pJrjcYru36/uJSZADfjsJOgILRB T74ZE3gIA3lF7TylNHRt1xNg7NnOUG9RvDrHO73YFYnI0XHybAJCBz2DlfRdAUA3ltUh lbPDIJEjWZLmlpC5dyQu1hmTG02TqmIM9GigfqfueBHfgSKI74qscpaztfylaluv2JR2 jeWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=Qm7wsKkc29j7D7uh+iJPFpU+0cHgvEtdvrqyGj2BgOU=; b=M4ppyEq/fM0Rdy9G5BRDKhvWhBLQtt1ZKfwy8jLL5XBbGuHIpU8uwjLQdTf24NRxw0 v2echHu/JOAUcmM3/Ov8V9ghJtm+mqD1epkXdvTVMPFEsaKgtXlu/5p4MP2XJ2R+52BG 9oBbsaI2LzGJYuGDYgvpfcFXOBlGb6VSDPW71HnkyyQa8EpXEVld8dJiRVmV1Xlq45Y5 vYRwHdEjMH3DNCDJUlAA2M7lmU04u3+AexBuDyM/jv4IgQKM42vL3GpGaBQHq4k5vW2Z rlO71vTvKx9JdBn29xOXJ7EHE9gbuFGIkkaOQTekDPmDVZcdl63pAOH2r/X0lwj61btL W8NQ== X-Gm-Message-State: AODbwcBi6hCarCP8uKdoNoza+iCgRpUeAO2nsBGwGQ8OhQGVoJaPWHlL 2q1hy8tX/Rjt55r0MA57ftzytYCsNQ== X-Received: by 10.176.93.36 with SMTP id u36mr3737799uaf.4.1496426703588; Fri, 02 Jun 2017 11:05:03 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.142.5 with HTTP; Fri, 2 Jun 2017 11:05:03 -0700 (PDT) In-Reply-To: <3A1C5448-F0A0-481E-8B42-3C47E5D6AB64@gmail.com> References: <1496415412.4363.66.camel@schlueters.de> <3A1C5448-F0A0-481E-8B42-3C47E5D6AB64@gmail.com> Date: Fri, 2 Jun 2017 14:05:03 -0400 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="94eb2c1be38419946c0550fdfebd" Subject: Re: [PHP-DEV] RFC proposal From: tendoaki@gmail.com (Michael Morris) --94eb2c1be38419946c0550fdfebd Content-Type: text/plain; charset="UTF-8" On Fri, Jun 2, 2017 at 1:36 PM, Rowan Collins wrote: > On 2 June 2017 18:21:34 BST, Levi Morrison wrote: > >On Fri, Jun 2, 2017 at 11:12 AM, Michael Morris > >wrote: > >> What about foreach by reference, which is honestly the only time I > >use > >> referencing anymore... > >> > >> foreach ($array as $key => &$value) { > >> $value = someOp($value); > >> } > >> > >> Is this also bad? > > > >I'm not going to say "bad" but I would not personally write it that > >way. If the memory cost is too high to duplicate then ... > > The times I've used foreach-by-reference have absolutely nothing to do > with memory cost. Mostly, they're situations where explicitly writing back > into the original array would be tediously long-winded, like this: > > $some_array[$some_outer_key][$loop_key]['foo'] = > some_func($loop_value['foo']); > $some_array[$some_outer_key][$loop_key]['bar'] = > some_other_func($loop_value['bar'], true); > > Granted, there are probably major refactorings that would be in some way > better, but changing $loop_value to a reference gives the much more > readable: > > $loop_value['foo'] = some_func($loop_value['foo']); > $loop_value['bar'] = some_other_func($loop_value['bar'], true); > > References are fiddly, but they do have their uses. Short of eliminating > mutability, per functional programming, I think they'll always have their > place, in some form. > > Regards, > > -- > Rowan Collins > [IMSoP] > Same here. I was just trying to keep my example simple. I agree that a generator, or even better array_map, would be a better way to deal with the simplistic example I gave. --94eb2c1be38419946c0550fdfebd--