Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108705 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 81324 invoked from network); 21 Feb 2020 00:48:42 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Feb 2020 00:48:42 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AD5B8180531 for ; Thu, 20 Feb 2020 15:04:57 -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=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS11403 64.147.123.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) (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:04:56 -0800 (PST) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id DF1E54C1 for ; Thu, 20 Feb 2020 18:04:54 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Thu, 20 Feb 2020 18:04:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=bKuXJI DXoBU7zpcgHcT0KtOf+Ew0/r7lxtQ+pYOseaY=; b=o8ki7AH4htkHdFiTKJQ3My I7vs84aM6D8QBmSqo3z0JOv+IvRauL8Cr2DkVkRdwoeltTaPeQFZpqc6E6/g3Bra 8dJ/v0FlhoPpGQhN4wcT09mTrwuanAoE2+B9R6aEGxOD9CqjkbuLDaumCiB2q3C+ 59LQ7CF8Fk7e4uVkx65oMNP76sHG9u5FFQZ79cePiooutHqLdvWBmNuQGAi67qcD 5zMGwr1PME9uR3r1hIs72f5oAvSZg1L2tX0ASkENXlA/ROynAOPw252FEC6SE0fU xYUiGsykdcIsoEo0mFxvo+4ucjsuYM19sGSe3iHzgk16gQBvzJFXjx8xtzGfCm0w == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrkeefgddtiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgrrhhr hicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh eqnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgr rhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 5976414200A2; Thu, 20 Feb 2020 18:04:54 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.1.7-802-g7a41c81-fmstable-20200203v1 Mime-Version: 1.0 Message-ID: In-Reply-To: References: Date: Thu, 20 Feb 2020 17:04:32 -0600 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC] Explicit call-site pass-by-reference (again) From: larry@garfieldtech.com ("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: > > function map(callable $f): Optional { > if ($this->enabled) { > return new Optional($f($this->data)); > } else { > return $this; > } > } > > 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. 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. --Larry Garfield