Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101333 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 9713 invoked from network); 12 Dec 2017 08:16:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Dec 2017 08:16:15 -0000 Authentication-Results: pb1.pair.com smtp.mail=johannes@schlueters.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=johannes@schlueters.de; sender-id=unknown Received-SPF: error (pb1.pair.com: domain schlueters.de from 84.19.169.162 cause and error) X-PHP-List-Original-Sender: johannes@schlueters.de X-Host-Fingerprint: 84.19.169.162 mail.experimentalworks.net Received: from [84.19.169.162] ([84.19.169.162:51500] helo=mail.experimentalworks.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B8/82-53433-E409F2A5 for ; Tue, 12 Dec 2017 03:16:15 -0500 Received: from [10.42.251.33] (x52717921.dyn.telefonica.de [82.113.121.33]) by mail.experimentalworks.net (Postfix) with ESMTPSA id 84BC56A2E2; Tue, 12 Dec 2017 09:16:11 +0100 (CET) Date: Tue, 12 Dec 2017 09:16:08 +0100 User-Agent: K-9 Mail for Android In-Reply-To: References: <1512911576.12039.8.camel@schlueters.de> <274a646a-4e56-81fe-ac52-015da2bebc6f@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable To: Stanislav Malyshev ,Nikita Popov ,PHP internals Message-ID: <17989A98-1247-4E3D-9585-26B9ADD36246@schlueters.de> Subject: Re: [PHP-DEV] [RFC] Explicit call-site send-by-ref syntax From: johannes@schlueters.de (=?ISO-8859-1?Q?Johannes_Schl=FCter?=) On December 12, 2017 8:51:42 AM GMT+01:00, Stanislav Malyshev wrote: >Hi! > >> The issue, as you well know, is that references disable >copy-on-write=2E Thus assume you have code like this: >>=20 >> function with_ref(&$a) { >> count ($a); >> } >>=20 >> function no_ref($a) { >> count($a); >> } >>=20 >> The count in with_ref() will copy the array, while no_ref() can use >copy on write and won't actually copy=2E > >Yes, this is an issue, and it'd be good to find a way to solve it=2E At >least for count() and other "pure" (however pure can it be in PHP) >functions it seems possible=2E But do not think "not using references >ever" qualifies as a solution :) For this case there is a good solution: Let the engine be smart and pass b= y value :-D And yes there are a few cases where references might be better: Graph like= structures (while I'd claim objects are nicer, but that's subjective), cap= turing by-ref in closures (`use` clause, while many times an object to hold= state can be, subjectively, better, but sometimes you just need a counter = or such) and returning error codes by-ref (if objects or exceptions aren't = better, this most often is more low-level stuff, i=2Ee=2E in json_decode() = I'd see benefits over json_error_last()) Some years back I spent quite some time with different cases almost always= removing the references gave faster and clearer code (while this proposal = to add & to the call sign takes away some wtf) not only in my opinion, but = also the respective maintainers=2E Of course with PHP 7 the maths changed a= bit, but fundamentally I stand by my opinion=2E johannes