Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89150 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 60188 invoked from network); 10 Nov 2015 16:49:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Nov 2015 16:49:11 -0000 Authentication-Results: pb1.pair.com header.from=phofstetter@sensational.ch; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=phofstetter@sensational.ch; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain sensational.ch designates 195.226.6.199 as permitted sender) X-PHP-List-Original-Sender: phofstetter@sensational.ch X-Host-Fingerprint: 195.226.6.199 mail.sensational.ch Received: from [195.226.6.199] ([195.226.6.199:38893] helo=mail.sensational.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 75/54-21426-40022465 for ; Tue, 10 Nov 2015 11:49:10 -0500 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]:33559) by mail.sensational.ch with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.76 and XAMS 0.0.20) id 1ZwC6T-0004ud-Ce for internals@lists.php.net; Tue, 10 Nov 2015 17:49:05 +0100 Received: by wmec201 with SMTP id c201so143198278wme.0 for ; Tue, 10 Nov 2015 08:49:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sensational_ch.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to:content-type; bh=hSJEYzWKrQiJo64SKIR3n/hfoZiMSr8eydiYDaeM4MI=; b=WIcv7AbeY5ZtUEQuS28NiYtFAPo88SvpB7pfgrSuV0OCEmF+gmhi/GpB0eGPuMfnb2 ieXyIQLjDnwLD+iAYIQyiBmZX1DQk6pn/ANsLrf610PCmdH2TAG6yrv9saLF71O1rCuw GxLZw1KTAhIbK6Q0CSvcMm8bcgALcltb1Jyv7Btf8+RGjgSJ4VFaHMJ3sOOzDkSqTELQ glYfogXpjZIwMlstiqIZJ7jPT4hcjztTEwwA6xii4t7kdu0e5DQvQKWPkzwpttKYXhfO 8Ia4qeecammqmKbFVoZG+KmGXw1vyubg5+DKxidKHkO55ZQoFCRiGdUF2TlJhYXBovkr 9KiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to :content-type; bh=hSJEYzWKrQiJo64SKIR3n/hfoZiMSr8eydiYDaeM4MI=; b=KeieexL8zmARD7/36g4sZcX+0SzaBp6vq8t0D9DqqYt8fD0ibidmQp8j2Ms56m2KGG hNp9FPJ6YdNOWiaoaOi5ll4kEciRtCEVtYp5XMYAwBzL0xEwDSMlS6hvszSNDK6+zkF4 rpVnQXgCRncDa3F5NJBm8UejD9238EvzYlJkIyZZxpxzH2QHJGFWD10obXXzRtKZwHbl E5opDmwWzexGVqT+MN5d3JdqeMg8NitZd85vBYdzRzW7wnFZf+KShdmPNWCYvPPmwTlp nviizBsTRyzuMGLdDpTMIYCaIp2npKbZWvZ66Wc2T26UUPAMAXQPkrPjRcKn3yULQCeH 2+1w== X-Gm-Message-State: ALoCoQmueJX7Jen790ufCxItvcPNMeWJCdV++oAm0puV1d1S8YjqWb+U1KbwBxbDbq92jxPh60zR9wiTNYqrPImYMAAfHlpQdoCwYDlE8wKxYtPiLE46ToryuHbQ0Zt3VIM12Hki3YbXB7KWd8X4lttGsCxhsgKG0A== X-Received: by 10.28.96.4 with SMTP id u4mr6479566wmb.52.1447174144026; Tue, 10 Nov 2015 08:49:04 -0800 (PST) X-Received: by 10.28.96.4 with SMTP id u4mr6479549wmb.52.1447174143837; Tue, 10 Nov 2015 08:49:03 -0800 (PST) MIME-Version: 1.0 Date: Tue, 10 Nov 2015 16:48:54 +0000 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary=001a1148e998c59f1c0524327c55 X-SA-Do-Not-Run: Yes X-SA-Exim-Connect-IP: 2a00:1450:400c:c09::234 X-SA-Exim-Mail-From: phofstetter@sensational.ch X-SA-Exim-Scanned: No (on mail.sensational.ch); SAEximRunCond expanded to false Subject: PHP7 / foreach / references / ugly code / discrepancy to PHP 5.6 From: phofstetter@sensational.ch (Philip Hofstetter) --001a1148e998c59f1c0524327c55 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi, 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. The code in question is ---- $b =3D [1, 2, 3]; foreach($b ?: [] as &$v){ $v =3D $v*2; unset($v); } var_dump($b); ---- in PHP7, this produces array(3) { [0] =3D> int(1) [1] =3D> int(2) [2] =3D> int(3) } whereas in PHP 5.6 and earlier, this produces array(3) { [0] =3D> int(2) [1] =3D> int(4) [2] =3D> int(6) } 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: foreach($b as &$v){ is fine foreach($b ?: [] as &$v){ is not. I guess this is related to http://php.net/manual/en/migration70.incompatible.php#migration70.incompati= ble.foreach.by-value or http://php.net/manual/en/migration70.incompatible.php#migration70.incompati= ble.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. Philip --=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 --001a1148e998c59f1c0524327c55--