Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89152 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72532 invoked from network); 10 Nov 2015 19:09:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Nov 2015 19:09:03 -0000 Authentication-Results: pb1.pair.com smtp.mail=php_m@rtin.so; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php_m@rtin.so; sender-id=unknown Received-SPF: error (pb1.pair.com: domain rtin.so from 209.85.220.43 cause and error) X-PHP-List-Original-Sender: php_m@rtin.so X-Host-Fingerprint: 209.85.220.43 mail-pa0-f43.google.com Received: from [209.85.220.43] ([209.85.220.43:36121] helo=mail-pa0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C3/16-21426-CC042465 for ; Tue, 10 Nov 2015 14:09:01 -0500 Received: by pacdm15 with SMTP id dm15so5128728pac.3 for ; Tue, 10 Nov 2015 11:08:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rtin_so.20150623.gappssmtp.com; s=20150623; h=content-type:mime-version:subject:from:in-reply-to:date:cc :message-id:references:to; bh=rFiBxn4BfzCgwcqfMnDsbslcUAgKWL3RlWVVRvbJ6Ng=; b=aUwVqHoOJyz3VLJtr1X0vTlQ4bWk3/qCbckmVLodOROTqDtKlM7zfQ/885zVSsYz9N 2M0h8zrfDc0Kzjjh91Fl3GrEF+Nu0cjanpfL0gumTo8vzAEmeCH0eF8JJXOCpzl0jn8H SgIZtQjXcQHtqjabukAPRyAw8ktDcFktSBmwTL+za+8nj9x+C7i0Z0XntJfF6lzv0c9M IZuVUrqESCnRtc62pXRAANHFlkRL6nM6bY0PAD4f+1YmwCAolRxK3WBKSqxDrvsBRAAp AGpqH8v7cZRlLDDvfLS/4L0iNLm4YIemVVpUwN9bcd+wDrrfVt2ue3+19aT/gHu744Cn wazw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:content-type:mime-version:subject:from :in-reply-to:date:cc:message-id:references:to; bh=rFiBxn4BfzCgwcqfMnDsbslcUAgKWL3RlWVVRvbJ6Ng=; b=XBlGqdwj7/CbSUmcUXo+6kyOp9WiMjaR1nEc5r7rOhAETGy19udiSvVqn+Xvt14ZHK NPo3rRIZUiwOD5tJj7YFliDzU/O1Y7bgkZQdklhD2x6UMAsDZcozNdwxRK/4LL9YUm5F cn7T1vLrqXY2epoz3NnKjDCgKUkl+7aVawNFXzYJg5l7lfN9mchqtBqX5/zLSk6OEOwh b/v4RXCBQLT2gUraHCOa5bMwRp5Ak2TGJpeEURB2pV2lTimhtNNKvbV6j7XBCYDMRuzj hF2X8o6N12VUM1syZMmDGpXdaYh47HHYJlrKvSRJyRry94M0hYh0KQJZZhz23iqpo51P f2Rw== X-Gm-Message-State: ALoCoQl4nwEe/oaqxrbnn6QKW7v5x78FC1X1ovfUV91uaGwhGIdIjWeF2Bk0aVeQc0kJB2dw5Pwv X-Received: by 10.66.227.170 with SMTP id sb10mr8063872pac.80.1447182537874; Tue, 10 Nov 2015 11:08:57 -0800 (PST) Received: from [10.0.0.38] (c-73-170-148-155.hsd1.ca.comcast.net. [73.170.148.155]) by smtp.gmail.com with ESMTPSA id oi3sm5494037pbb.53.2015.11.10.11.08.56 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 10 Nov 2015 11:08:57 -0800 (PST) Content-Type: multipart/alternative; boundary="Apple-Mail=_C48CBAEA-677C-415C-9A07-8B88112BAC29" Mime-Version: 1.0 (Mac OS X Mail 9.1 \(3096.5\)) In-Reply-To: Date: Tue, 10 Nov 2015 11:08:55 -0800 Cc: PHP internals Message-ID: References: To: Philip Hofstetter X-Mailer: Apple Mail (2.3096.5) Subject: Re: [PHP-DEV] PHP7 / foreach / references / ugly code / discrepancy to PHP 5.6 From: php_m@rtin.so (Martin Amps) --Apple-Mail=_C48CBAEA-677C-415C-9A07-8B88112BAC29 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Here=E2=80=99s a 3v4l demonstrating this too: https://3v4l.org/OXAd3 > On Nov 10, 2015, at 8:48 AM, Philip Hofstetter = wrote: >=20 > Hi, >=20 > I'm having a cause of slightly ugly code that runs differently from = PHP 5.6 > to PHP 7 and I don't think this difference is documented, nor = expected. As > I'm not sure whether this is an intended change or not, I'm asking = here > firstr before making a bug report. >=20 > The code in question is >=20 > ---- > $b =3D [1, 2, 3]; >=20 > foreach($b ?: [] as &$v){ > $v =3D $v*2; > unset($v); > } >=20 > var_dump($b); > ---- > in PHP7, this produces >=20 > array(3) { > [0] =3D> > int(1) > [1] =3D> > int(2) > [2] =3D> > int(3) > } >=20 > whereas in PHP 5.6 and earlier, this produces >=20 > array(3) { > [0] =3D> > int(2) > [1] =3D> > int(4) > [2] =3D> > int(6) > } >=20 > what scares me about this is that in order to get the old behaviour in = PHP7 > back, you just have to get rid of the ?: operator: >=20 > foreach($b as &$v){ >=20 > is fine >=20 > foreach($b ?: [] as &$v){ >=20 > is not. >=20 > I guess this is related to > = http://php.net/manual/en/migration70.incompatible.php#migration70.incompat= ible.foreach.by-value > or > = http://php.net/manual/en/migration70.incompatible.php#migration70.incompat= ible.foreach.by-ref, > but I'm not entirely sure whether this is actually intended behaviour = - > it's certainly unexpected to me that applying ?: now always makes a = copy > whereas before it didn't. >=20 > Philip >=20 >=20 >=20 > --=20 > Sensational AG > Giessh=C3=BCbelstrasse 62c, Postfach 1966, 8021 Z=C3=BCrich > Tel. +41 43 544 09 60, Mobile +41 79 341 01 99 > info@sensational.ch, http://www.sensational.ch --Apple-Mail=_C48CBAEA-677C-415C-9A07-8B88112BAC29--