Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101335 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22593 invoked from network); 12 Dec 2017 13:45:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Dec 2017 13:45:27 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.43 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.214.43 mail-it0-f43.google.com Received: from [209.85.214.43] ([209.85.214.43:37887] helo=mail-it0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 85/A3-53433-67DDF2A5 for ; Tue, 12 Dec 2017 08:45:26 -0500 Received: by mail-it0-f43.google.com with SMTP id d137so24352445itc.2 for ; Tue, 12 Dec 2017 05:45:26 -0800 (PST) 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 :cc; bh=PAgBslPyUj84LRs1LI00A854ysHVmeNNSGTtrGU+WTs=; b=PrOzKvKBZtNgWG/YTvxl6O5/S78gK/fUmpzvaZoYZUo0YGnJ05rqMb/5lPooOc4UQa 3PUrDOwD8TmtDSTjZ6VHtUJu4rh/LlHZYHPCvwJnx+QQf41Ts+aV7qxbp5MX73fovPUN bb/AOi/FQi25m2lT4cBJP5UVIkIuvfw5rePWzhoZr2jETUTcxOSX5SGtLSDVYgnDy6mI +iav5GY3wcgVUd5a6d+jy2gxNv7XAsLUbQYjCWdF2K2A7gA6inzwE6jNUjzR/A2fs6i4 L9MFq3L3+gtERs6up2b1ELfsLyUio3u1XvcWHJtvO9p5hWYBbm9MiMTXBYW7D7iI0vZG 18wA== 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:cc; bh=PAgBslPyUj84LRs1LI00A854ysHVmeNNSGTtrGU+WTs=; b=s3Gezw9/ZOEjk+O4Krqz6kvHIfpTTkAGRYXYsqAfG7XDRAxXpbHAvtjmzaT9UJx41L yZZgznA2HzxD0JNgYmVITvv77XHHv408otsbD5oBF1Tx9/UfdBot2blQ8fvxLlsFqB0e +sSR+Tg5Y4Eka1MXUoh4ivHa9+RmSoFmZIM7Twer7FufhEKZGVrgtnu3v7ezg86kMhcs 2VK86Cy1WUvglKqRWRcy0qztXY3PhZ8CI/MoLlQ49aJprzXR8ycaCaAS2pv9C/Tzp27X 9oOsB99h9c7RQlPBt5+HIieovupDmZ1Jwx1zgwAvFvgu00RsdsO4JDfCaM+0DPprEF/z ER2A== X-Gm-Message-State: AKGB3mIJtSlynosNbKe7IsrbEm54iaTd/+JobshaQ1TvxQUUfPTL2n5E vNRe5J26R9YonQrNNcggKZFTHd7uN/ARj5Dx6q0= X-Google-Smtp-Source: ACJfBotaRP8RPxl7uR5TAg0UaHp+5W0OisjmXdsbN7zsyoA3pzAP8qgmjum7ST6sWbIdXYL1pZuhyAO3jVVeZmR+CtQ= X-Received: by 10.36.37.2 with SMTP id g2mr2507768itg.107.1513086323804; Tue, 12 Dec 2017 05:45:23 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.138.93 with HTTP; Tue, 12 Dec 2017 05:45:23 -0800 (PST) In-Reply-To: References: <1512911576.12039.8.camel@schlueters.de> <274a646a-4e56-81fe-ac52-015da2bebc6f@gmail.com> Date: Tue, 12 Dec 2017 14:45:23 +0100 Message-ID: To: =?UTF-8?Q?Johannes_Schl=C3=BCter?= Cc: Stanislav Malyshev , PHP internals Content-Type: multipart/alternative; boundary="001a1143d1fcd84e18056024dca0" Subject: Re: [PHP-DEV] [RFC] Explicit call-site send-by-ref syntax From: nikita.ppv@gmail.com (Nikita Popov) --001a1143d1fcd84e18056024dca0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Dec 12, 2017 at 8:43 AM, Johannes Schl=C3=BCter wrote: > > > On December 12, 2017 7:38:54 AM GMT+01:00, Stanislav Malyshev < > smalyshev@gmail.com> wrote: > >Hi! > > > >> I would rather discourage usage of references. Since PHP 7 the cost > >of > >> breaking cow isn't as expensive anymore, but receiving values by > >value > >> and returning by value is more idiomatic imo. Using objects can be > >more > >> efficient. > > > >Objects are kind of overkill when you just need a modifyable array. And > >copying an array when you just need to add one value to a K-size array > >is still not a good idea for many apps. O(n) vs O(n^2) still matters. > >One should definitely be careful not to overuse refs, but there are > >still valid cases for using them. > > The issue, as you well know, is that references disable copy-on-write. > Thus assume you have code like this: > > function with_ref(&$a) { > count ($a); > } > > function no_ref($a) { > count($a); > } > > The count in with_ref() will copy the array, while no_ref() can use copy > on write and won't actually copy. This is no longer the case as of PHP 7. PHP 7 can share values between references and non-references. Nikita --001a1143d1fcd84e18056024dca0--