Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108710 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 15526 invoked from network); 21 Feb 2020 04:13:17 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Feb 2020 04:13:17 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 047541804DA for ; Thu, 20 Feb 2020 18:29:33 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f195.google.com (mail-yb1-f195.google.com [209.85.219.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 20 Feb 2020 18:29:32 -0800 (PST) Received: by mail-yb1-f195.google.com with SMTP id b4so432652ybk.11 for ; Thu, 20 Feb 2020 18:29:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xMzhy4ku6HuNCrHHa8Xx1ubEPmTj3SpTX/LSTmKVcg4=; b=IWURqVWKR/pIHEsDSVXxo1AIEZuxpjssCuJHLIfYEuhQV19/lEZF5DpekhoUm7W2cC 7k6UgAbrr2pf0qq0FvEzbXXAdlEWUrp/8Qh4N4WKST4LlT7xCICeaD7bS52Rf3WcjoIg Eym58A9B8dULjONm3mb4NjG8BJi/GFViy6TQ0A+u+x2pZuq058SSkikPUOkJ6FJM+yEA LDURp8y6vPkChMBipPsfr5gOCvMlqUggUWsPMmXoJ0N6v0hkD5NOSaORjP1Baqz9Luzg N4C201mU9q8v5vwVsSGWE5jsSstfjLUlBbLJmgI0AEKlC/8PEQtKxWv+S/rcnwmx1u4L 6Few== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xMzhy4ku6HuNCrHHa8Xx1ubEPmTj3SpTX/LSTmKVcg4=; b=LBWWUQa1BFjd9B68DCBda1Gl8i04X4CKitKqgpJ7q6vgpjI9RVMWI0NxAaLR9r1avt D3sMwCXE602lr74A+FFK/RK69niG6xp+rfW63c+f10pSp0/cpQA7Jq6FoaNe36kMeRpc /t74yUTpczeub/Xy+/VxPfNx9AU+5RSTSwa7ZQTQ+oKFHvgmykcnGqHuO5RRxerzQscs bnARzfrtjcyhMAFqDaCCwIjXF22hvk5U4ukiMkyvr73ryl4SIYEhbvGVUTaFQI2rgLJj DGNu1ioWAB4O8ppVZPBbUyHjTd75gvtPSYNIhV7brfJSbfSNsVV8IPAwHDXTaoDjV34C 51ng== X-Gm-Message-State: APjAAAXNYP8oQ3FCyIQU1uooy9vHri8CQkYRKYQioKWA+8oWT0d4Vm3E 0jzPqlyvs5ed9l4Tsqat1F5Ilkwf+bXVh45eqqI= X-Google-Smtp-Source: APXvYqzuY8cDdQtaUrRzsoaAEOBvKMQc6dJoIimNtwicC+vb2dmQPMgHZMAvDdFAztR9g2KWyQIJwCa4yfosEgIjY00= X-Received: by 2002:a25:b9c8:: with SMTP id y8mr28769145ybj.369.1582252169600; Thu, 20 Feb 2020 18:29:29 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 20 Feb 2020 21:29:18 -0500 Message-ID: To: Levi Morrison Cc: Nikita Popov , PHP internals Content-Type: multipart/alternative; boundary="00000000000083a368059f0ccad5" Subject: Re: [PHP-DEV] [RFC] Explicit call-site pass-by-reference (again) From: matthewmatthew@gmail.com (Matthew Brown) --00000000000083a368059f0ccad5 Content-Type: text/plain; charset="UTF-8" This proposal is great, but most PHP static analysis tools already do a reasonable job of understanding by-reference assignment and detecting bugs there (an exception is closure use by-reference checks, which is a static-analysis no-man's land). No static analysis tools catch your specific use-case, though. On Thu, 20 Feb 2020 at 09:48, Levi Morrison via internals < internals@lists.php.net> 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. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --00000000000083a368059f0ccad5--