Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109044 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 8421 invoked from network); 16 Mar 2020 00:35:11 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Mar 2020 00:35:11 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A95551804E0 for ; Sun, 15 Mar 2020 15:57:27 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS8075 40.64.0.0/10 X-Spam-Virus: No X-Envelope-From: Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11olkn2041.outbound.protection.outlook.com [40.92.18.41]) (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 ; Sun, 15 Mar 2020 15:57:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MUYPyeMLjgGCATP01q8/k0ijPv43extygFq6fjGTPuJyIByH0tVZsUUvMU3TrhdR8/uq5pwLHjt81h7pAwaeQBk8bJT+ObYBCPi32GPHSgYmmaslezAnOo9YL44Rr8YNR2wOBti5fNIv06gy/W/8zCjKsJ4xWjEYpiVo71KqJPGKhi8Zd2j2bChmI6Gp1hcQI+eegxXNstLwsOu8E+4XSHK2l8dfcK9UCV5N5YkywyRiycn1OtGy82HXC2Z4CFmOCX459hVnLqfYKfaZbtOyW+rcEGdxWes9a+48EtSWCgNsC/rrDKDNcq+l8RViSG3VRMRISPsLstF3Y0JcZ3NpJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mr6pZSkB27AjgL5JtLOK7XR1GL/VWfaYXGkjpcpJzss=; b=MFOxSaPdQJZNHCGuM3mFvInfip6rVyHr/gGkvQ4X3TRnT4P3EKs2+l1QBcGMcfCh4LakzUUr8fTudH0+FmZah/LXrIx6xUDdRk55j8HKhVAeEWNHGXn9g02OHNhV4fyKuOAkn5ua9oWZECl8rAULH//gIS2Fs1rd3VFJTCQ586O0/aO8xQHLRhM/e06XJoKDCU5LLs7oFhIJ0jOPSUiZM69ftktvrBXBfHA4DMapGwLXoPQfHKqTEspQMt1+ZHuW9reZEpvR0xcGZhp7/Tetv2swkEkvvefDMqHwPtCN94Tt62SiC+ycWNN+0r8kF44Ek3P5l/FkVnboL5ga2q6LkQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mr6pZSkB27AjgL5JtLOK7XR1GL/VWfaYXGkjpcpJzss=; b=U5KovK95FbCZa/zUa8QpgEKsZs6Qo9JTqDBvsBypn8YwjQmL3uMuzPEfE4bjYYFzDPDgoAmDhZy+XxAshZi5zAYxLrIl7it/7SUbQyADxW+/ZBJY/GndsDzi0ns5TSubFsTppiSpI8mJVTDBmxfJ0AkNvueKaWcyLCW3UdOanwUfvz31n6AFXJhqk7H1TJtwUC3bnhoVwURsN1gMJM/UhPvRPcAT3i9FhySkTmljKTojtGtGk4yCk0xpqSQ9NJxGmao3mWjmZVVMdNvGDOH6UP4sUw5Ynh/LAdIYUBP5ddSuvyuy8iNsGYKtIKnId7vsUBBxzy4gZ9xJRLiQYHQQIw== Received: from CO1NAM11FT022.eop-nam11.prod.protection.outlook.com (2a01:111:e400:3861::33) by CO1NAM11HT032.eop-nam11.prod.protection.outlook.com (2a01:111:e400:3861::210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2814.13; Sun, 15 Mar 2020 22:57:25 +0000 Received: from DM5PR07MB3067.namprd07.prod.outlook.com (10.13.174.56) by CO1NAM11FT022.mail.protection.outlook.com (10.13.175.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2814.13 via Frontend Transport; Sun, 15 Mar 2020 22:57:25 +0000 Received: from DM5PR07MB3067.namprd07.prod.outlook.com ([fe80::1133:bcac:caf1:d588]) by DM5PR07MB3067.namprd07.prod.outlook.com ([fe80::1133:bcac:caf1:d588%3]) with mapi id 15.20.2814.021; Sun, 15 Mar 2020 22:57:25 +0000 To: Rowan Tommins , "internals@lists.php.net" Thread-Topic: [PHP-DEV] RFC idea: Block scoped variables with "let $x = expr" Thread-Index: AQHV+ug0CGaQ9aFqj0aNq48f2k+kqahJ7oQAgAACegKAACLlgIAAL5O8 Date: Sun, 15 Mar 2020 22:57:25 +0000 Message-ID: References: <77731b0f-70d9-788c-f6bf-7663542aaa7b@gmail.com> , In-Reply-To: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:AC260EE172A09526DF116605B30B53BBB1712518CD6D93B3995D611A1AA303C3;UpperCasedChecksum:0E823A6F185B2BDD27BE521C6EE2816908C52AB84D976F48B790C287C374EDDD;SizeAsReceived:7357;Count:45 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [sy0zPaRxJIv0zKk2K3dJ/X/2QPZlmVGlhXzwbP1oHpyKuOnyWRmgemgS5WsTNoEH] x-ms-publictraffictype: Email x-incomingheadercount: 45 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 0937263c-4e89-42a5-a9b1-08d7c9343aa0 x-ms-traffictypediagnostic: CO1NAM11HT032: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 0rh+tPHQkG/XaimHUQZ3uEGAcOKWYDAfqawSA3vQZxIMY3EukgTu6/gEmXddicS8NTq4iEBcesY0atS47o0GgWs838YPOdu0JN8//Cnhy7oEWN0QQonSqGNG0+SCIn8jeoLaLdFxSiq6wII/AA1Bih0zSWNK0PjlTFbqoSujPtaDMlH0tTmeWpdYrI5EcCUQ x-ms-exchange-antispam-messagedata: 7s0ktHQejakac/O6vzNxk7Wf44wbqtbRLO8hWLtNWJzsiWEOV15CpAyVdeHQvITf/8GMXhcsACDr36AYmdXa0KgDsOPWeqGQjW6m4zfzxJALJh/nI6wQKk1nzgAGQUr57bxWZq8I+h6CCpMiMiwEJfkWnqMTnLKQOxb4aofDI9gpO3jL0DdeoQZfWoehbueh+APb4Y3VtUV44N7TIWEOhA== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 0937263c-4e89-42a5-a9b1-08d7c9343aa0 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Mar 2020 22:57:25.4944 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1NAM11HT032 Subject: Re: [PHP-DEV] RFC idea: Block scoped variables with "let $x = expr" From: tysonandre775@hotmail.com (tyson andre) Hi Rowan,=0A= =0A= > Do you know how the equivalent code works with function-scoped variables?= =0A= > As far as I can see, returning from a function will successfully call mul= tiple=0A= > destructors even if one of them throws an exception. Could exiting block= =0A= > scope use that same algorithm?=0A= =0A= PHP literally frees all of the variables (even the ones which are definitel= y not reference counted)=0A= without stopping if any of them throw an exception until everything is free= d.=0A= `i_free_compiled_variables` is called when exiting the function scope (e.g.= throw/return).=0A= (the caller also decreases reference counts to the closure/$this, extra une= xpected arguments, etc)=0A= =0A= ```=0A= static zend_always_inline void i_free_compiled_variables(zend_execute_data = *execute_data) /* {{{ */=0A= {=0A= zval *cv =3D EX_VAR_NUM(0);=0A= int count =3D EX(func)->op_array.last_var;=0A= while (EXPECTED(count !=3D 0)) {=0A= i_zval_ptr_dtor(cv);=0A= cv++;=0A= count--;=0A= }=0A= }=0A= ```=0A= =0A= > Having the variable become inaccessible but not actually deallocated=0A= > seems like it would cause a lot of confusion.=0A= =0A= Good point about resources, I forgot about freeing being automatic.=0A= =0A= I'm starting to lean towards deallocating.=0A= =0A= If this was used within a try block or a top-level statement,=0A= this could probably add a new opcode to free a variable that could throw=0A= without checking for the exception,=0A= and only the last opcode would need to throw the last exception.=0A= (adding a new opcode to ensure deallocation of all variables without the eq= uivalent of=0A= a `try/finally` block for every additional `let` variable)=0A= =0A= For global variables, there's already the problem in the engine that `__des= truct()`=0A= could itself create global variables of the same/different name.=0A= =0A= - Tyson=