Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108706 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 85263 invoked from network); 21 Feb 2020 01:09:51 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Feb 2020 01:09:51 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F312A18050B for ; Thu, 20 Feb 2020 15:26:07 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS1836 195.49.0.0/17 X-Spam-Virus: No X-Envelope-From: Received: from darkcity.gna.ch (darkcity.gna.ch [195.49.47.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 20 Feb 2020 15:26:06 -0800 (PST) Received: from flatter.home (unknown [IPv6:2a02:120b:2c4e:2460:3598:619f:efce:1c90]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by darkcity.gna.ch (Postfix) with ESMTPSA id 0CE926C152D; Fri, 21 Feb 2020 00:26:04 +0100 (CET) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\)) In-Reply-To: Date: Fri, 21 Feb 2020 00:26:04 +0100 Cc: php internals Content-Transfer-Encoding: quoted-printable Message-ID: References: To: Larry Garfield X-Mailer: Apple Mail (2.3608.60.0.2.5) Subject: Re: [PHP-DEV] [RFC] Explicit call-site pass-by-reference (again) From: cschneid@cschneid.com (Christian Schneider) Am 21.02.2020 um 00:04 schrieb Larry Garfield : > On Thu, Feb 20, 2020, at 8:47 AM, Levi Morrison via internals wrote: >> Just chiming in to voice strong support for this RFC. This is a key >> piece toward making PHP code statically analyzable. If it becomes >> required at the call site, such as in an edition of the language, it >> will significantly enhance the ability to reason about code and >> probably make it more correct as well. As a small example, consider >> this method on an Optional type class: >>=20 >> function map(callable $f): Optional { >> if ($this->enabled) { >> return new Optional($f($this->data)); >> } else { >> return $this; >> } >> } >>=20 >> The intent is to return a new optional or an empty one, but if you >> pass a closure that accepts something by reference you can change the >> original, which is not intended at all. For people who defend against >> it, it requires saving `$this->data` to a local variable, then = passing >> in the local. Then if the user does a call-by-reference it will = affect >> the local, not the object's data. >=20 >=20 > If $this->data is itself an object, then you have a concern for data = manipulation (spooky action at a distance) even if it's passed by value. = Given how much data these days is objects, and thus the problem exists = regardless of whether it's by value or by reference passing, adding = steps to make pass-by-reference harder doesn't seem to help much. +1 The whole discussion about being worried about 'malicious' libraries = altering your precious scalar values misses the fact that PHP is not a = pure language, there are many ways a function can have side-effects, = Larry pointing out one obvious one. Speaking of language editions: Trying to solve one obscure case (and one = which is easily enough detectable by statical analysis) by introducing = such a big BC break could render a whole edition ineligible for a = software project. So beware, features bundled in one (hypothetical) = edition better not break too many different things at the same time. If you don't trust your library code then you're in deep trouble anyway. - Chris