Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111391 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 29891 invoked from network); 9 Aug 2020 15:42:50 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Aug 2020 15:42:50 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DCFDD1804D9 for ; Sun, 9 Aug 2020 07:41:46 -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,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10olkn2021.outbound.protection.outlook.com [40.92.40.21]) (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, 9 Aug 2020 07:41:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CI9/Ty/iBVjdEKjUr/R7L6Yxwjz5ne7aO8RJIgEnmZmPINTtr+TrgFM3v+9VbonmXqKz9Y/YSpET0238qjhDfmalHgZLSaJ+DF1wQfnqffyWvRalDkyhnZJqlCqjg1W/P+Ci3QwJxCEMSPC8dZNmJTiM+jNuqNzP5VOvRaKaUXGVGM/yO+vPHLiFbxu4xkTsmaQakWlh/maq8YSKf0vJcxMXJ7+ikmFqRPsGFgceWCTRGVGX3+e5cYrBFVUPpZdrw7ipUt/KBIw5yAr+AH51NGmoLY3RZ3sLz8vM1ZtVpMUd77oEJ8Uu5UJb5ZY1i2m00m8DNbRL0i2ENBXlF50NXw== 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=FIcB0xuf4l6tZKP3GPx+45fM2sobdTX3U0tRlagqh1s=; b=dL5+AJo9IfyG366ng0tHg7YW9YV2IA/Qk2S0rtfVt+FIUODAPuEtWiJkQM5/J/wQQQ5y7PF3ANzV0db/kRlpHuw061MSIQ6GtQKOmzwwrWCZeHBUgIgISHPa0WcOYDlAAnQhJLHSqTV8WsBxz0hhhxlKyeNyM/DPXSZNIW70y1WEga4Tc07wbOM2D5H3wUTOOAK6u3dadaul6dyrJSdm/zzPqnr1LQAZ9hbaNhNq1Q/Mla2D2H8R+fM5TCxa6n8QadahY4BahmiTKlmqD6E9bFjoAzJgzdcGbxRR/5VIQ3gsG/WzWaoYzwdd4zirVSHq/ivb8wBlnsF8LLUT9rCUzw== 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=FIcB0xuf4l6tZKP3GPx+45fM2sobdTX3U0tRlagqh1s=; b=bn0FLdxTwNfT4+Ti0y+QfRGfvNZo27d58tUBeD/tyN3qXuT0wi4gh7uwhJDUEumN+NYQkGaeQTbpTs1zoA9GlA3XpicgCXRismBaUWxkhM99AOlXA/uyjsjK5W9wW3YXF8tRIZeaHEMRjUPQasjcMYwlcKUQuWCtZXz7HkojTuSA1aTsmnOjBq8a7RV5Pw97CpLpphyXt4Wg0/F3+H7iSPaoy3VmiaF1Nb02VXMjdqA1Y4H9fgBRBP0StxNNe3VXlaNzRPTTYiSrjalr3NS+GZ3NeQaDgMGFWzv7JIAT4vBmsZChqd240/4tsxxOFYoogv0yE3l/txSBy0ws9eLm1Q== Received: from DM6NAM10FT054.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e86::4e) by DM6NAM10HT110.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e86::455) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.16; Sun, 9 Aug 2020 14:41:45 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:7e86::53) by DM6NAM10FT054.mail.protection.outlook.com (2a01:111:e400:7e86::423) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.16 via Frontend Transport; Sun, 9 Aug 2020 14:41:45 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::cc10:a3e2:1dcf:adc1]) by DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::cc10:a3e2:1dcf:adc1%6]) with mapi id 15.20.3261.022; Sun, 9 Aug 2020 14:41:45 +0000 To: Manuel Canga , Internals Thread-Topic: [PHP-DEV] [RFC] Import of variables Thread-Index: AQHWbivMtW2Ip/Py5Eaza6g/2BjAe6kv1QQM Date: Sun, 9 Aug 2020 14:41:44 +0000 Message-ID: References: <173d2736435.eeebc066559719.6668730031195302987@manuelcanga.dev> In-Reply-To: <173d2736435.eeebc066559719.6668730031195302987@manuelcanga.dev> Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:C054906B76FF7CD45BBE2842333BA2F1CBB55360B6C4770B5951F74091695EA5;UpperCasedChecksum:4D88748C9C848B3C6F16EA9CEB8ED14F46C8B6D11C913F8317C3E770DD08F8F4;SizeAsReceived:7030;Count:44 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [T3Eg02M6RuxWwjBcTzFr4+wmIPqcyXlLeDGNJbslTPDDfyFP+No65767+rhEQZcb] x-ms-publictraffictype: Email x-incomingheadercount: 44 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: fedd7b5c-c319-45f8-d812-08d83c72569e x-ms-traffictypediagnostic: DM6NAM10HT110: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: cTOqbDyDlT+SW2t5IruXWMii6Lai0tbmATi3ADBbdEVl2T55xMXjt2KFy1bgW8WPY1qdMlJmNgGRNWBtwNX8ELdrKesUdMtDbyHk0qfV8p1nuhOpit+YhfL374yj7F8CiqQgbmTH34XlKy04JilHyEiHzN3yZei6k5BZZBi1ltjY0mmjzCJ1DhvJANw1M/enAdqLmiD8tdtEcULLExNYQmv+EdJCHbbceW+qJzoKuEsmtOS7qwv8OkZoFQ3l2CKV x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:0;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR07MB6618.namprd07.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:;DIR:OUT;SFP:1901; x-ms-exchange-antispam-messagedata: DL/uy+Eo7kRn4Yu1uLmQx2F0dtFdXm9ZROuwxXB+8Pvi+cwBHZ2iZQRPoGIR31f4Awg3AITaaJx5WTQGfRHsNk/Pfiu7bPYyzbWIRZDrE5vksu/Pd4/EcOhsxfjK/k8MrNNrBc2FQn7aCXZffGFRN6es7DktRkaNTyQU6A2e5U/CP4dcLQuP5KNgYULLp2vtXQ/zn72mfHhN17FDl46HHQ== 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-AuthAs: Anonymous X-MS-Exchange-CrossTenant-AuthSource: DM6NAM10FT054.eop-nam10.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: fedd7b5c-c319-45f8-d812-08d83c72569e X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Aug 2020 14:41:44.8944 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6NAM10HT110 Subject: Re: [PHP-DEV] [RFC] Import of variables From: tysonandre775@hotmail.com (tyson andre) Hi Internals,=0A= =0A= > This functionality would allow to create a new=A0 'use vars' keyword in o= rder to can use( or cannot use )=A0 global variables in local scope( of cur= rent file ).=0A= =0A= To be clear: The variables in the top-level scope depend on what has requir= e()d/include()d a file.=0A= The top-level scope starts off as being global, but if a file is required f= rom within a function/method/closure (e.g. the autoloader closure), then th= e top-level scope in the require()'d file uses variables (e.g. $this) from = whatever context called require().=0A= =0A= It may be possible to use a declare syntax, e.g. declare(used_variables=3D'= all') for `'all'`, `null`, `['var1', 'var2']`, etc.=0A= - Otherwise, you face the issue of where `use vars` should be allowed, what= happens if there's a statement before `use vars`, etc.=0A= =0A= I can see this as having some use cases, such as in configuration files or = files used for bootstrapping.=0A= For example,=0A= =0A= ```=0A= "$api_base/new",=0A= 'url_all' =3D> "$api_base/all",=0A= ];=0A= ```=0A= =0A= This feature (ignoring the question of syntax) would ensure that people rea= ding the file knew that $api_base was not modified by other files=0A= and that other files did not read local variables created within a configur= ation/bootstrapping file in unexpected ways,=0A= which is a fairly common issue in some web apps I've worked on.=0A= Opcache would also do a better job at optimizing code if it knew which vari= ables in a top-level scope couldn't be modified.=0A= =0A= That being said, there's been opposition to extensions to the language that= add functionality that can be implemented in other ways, as in Rowan's com= ment,=0A= but peoples opinions depend on the specifics of the proposal=0A= (e.g. `match` was added and was more performant than chained conditionals o= r switch).=0A= =0A= As Rowan said, there are ways to reimplement this:=0A= - Wrapping the config file or bootstrapping file in a closure, global funct= ion, or class method=0A= - `function safe_require_once(string $path, $vars =3D []) { extract($vars);= require($path); }` from the caller, to limit what variables are passed in.= IDEs/tooling would be worse at telling you if a file name had a typo, thou= gh.=0A= =0A= Regards,=0A= - Tyson=