Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109039 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 82549 invoked from network); 15 Mar 2020 21:41:45 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Mar 2020 21:41:45 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 527AC1804E2 for ; Sun, 15 Mar 2020 13:03:59 -0700 (PDT) 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, 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-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 ; Sun, 15 Mar 2020 13:03:58 -0700 (PDT) Received: by mail-wr1-f50.google.com with SMTP id w16so2223786wrv.13 for ; Sun, 15 Mar 2020 13:03:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=uu+npLubsLTj0swwrPtmt1eKasFgJsXgdiG9c8PUoYg=; b=VR2Wv8nbQouiq+7oUp6fdKBKhnj8UmRfiXooFuDWmOWurosjNV1MSMHh2GDD8ldzFH 5PBNrKV7v6uVrBnsgVa+haEuJ7OkkkSETSAV4ndoQF0nPRex0jYbDCATKH4s+1nl0rsT nftUYPL9tNi9mqAcTydR4dXh6n29eOaeHd0weVhwMAtQctJ8gD0sqD4nsZftkRwplIdU dUYrWyUdut1Vz1EmivN3FU3+i/QhaXFksP8tKhGLVlkNvHcpnNrjlQeBb2Yf6kJUEaDy X8vaT/rS+yozmXRHGiUTGrIMQZkImsEjVNC0+GF6SHQjK8FZFGH3VFr5lTA2wGbSpE4I kxmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=uu+npLubsLTj0swwrPtmt1eKasFgJsXgdiG9c8PUoYg=; b=nrAbHM/wwoTht7i1M+Hr1rqUXbnvDsORjLYEBUi9zVfzssxxm0u+BawrF+9I8IYyUr 5fU0BxDvUGSqCJNcyl1zEhRAHexNMgXUdy4q/SZXIfKWNm/00LnVfJC4OTMsbZftlWt/ IpN6Pmi/XPb1EllemSIv6SwQTlZ1m093KZrRU1pcPygEQAigM45a/Q1yvouxcxDJGQ5S zgQ/oEkS4lLVmsSvdUTBzdeotqKfCM1wucSFi9x6PqKIRS7RDIiDL2rrYjGC6itP+FdT tEzQSA9cnUWSdYnIipxSxpPb+05W8cX+ojeNt164+I7QOHbqaoJAnvr2LkHflgAybbo5 UDlA== X-Gm-Message-State: ANhLgQ0tnFpiM/sAnrFIkZLNUFCq4xgi3UhIjOHhoK1BAlz7BgYx5nEU ztKCnLSM3DMyjXzGwkdLelLjyeTZ X-Google-Smtp-Source: ADFU+vuI9EBOLBsJzfaaPh3Zmb+4fFE+XWLegoSxQNrpeexrxaPT0e7U9PKJOMNIa37MVq47ehjl7g== X-Received: by 2002:adf:f505:: with SMTP id q5mr30818783wro.348.1584302634817; Sun, 15 Mar 2020 13:03:54 -0700 (PDT) Received: from [192.168.0.14] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.googlemail.com with ESMTPSA id b4sm3582858wmj.12.2020.03.15.13.03.53 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 15 Mar 2020 13:03:54 -0700 (PDT) To: "internals@lists.php.net" References: <77731b0f-70d9-788c-f6bf-7663542aaa7b@gmail.com> Message-ID: Date: Sun, 15 Mar 2020 20:03:53 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] RFC idea: Block scoped variables with "let $x = expr" From: rowan.collins@gmail.com (Rowan Tommins) On 15/03/2020 18:17, tyson andre wrote: > If this feature freed variables when going out of scope, > it would be compiled more like the following (if there were multiple lets): > > JavaScript doesn't have destructors, but PHP does, which makes the implementation a tiny bit more complex. > > ``` > try { >     $x = new Foo(); >     $otherLet = new Other(); >     $x->bar(); > } finally { >     // try/finally is useful if unset($otherLet) could throw from __destruct >     try { >         unset($otherLet); >     } finally { >         unset($x); >     } > } > somethingElse(); > ``` I'm still not 100% clear why all this would be necessary. Do you know how the equivalent code works with function-scoped variables? As far as I can see, returning from a function will successfully call multiple destructors even if one of them throws an exception. Could exiting block scope use that same algorithm? Having the variable become inaccessible but not actually deallocated seems like it would cause a lot of confusion. For instance: {     let $fh1 = fopen('/tmp/foo', 'wb');     flock($fh1);     fwrite($fh1, 'Hello World');     // no fclose(), but $fh1 has fallen out of scope, which would normally close it } {     let $fh2 = fopen('/tmp/foo', 'wb');     flock($fh2, LOCK_EX); // won't obtain lock, because $fh1 is still open, but no longer accessible } Regards, -- Rowan Tommins (né Collins) [IMSoP]