Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108280 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 70415 invoked from network); 28 Jan 2020 04:26:29 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Jan 2020 04:26:29 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E8498180511 for ; Mon, 27 Jan 2020 18:36:47 -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=-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 NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10olkn2068.outbound.protection.outlook.com [40.92.42.68]) (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 ; Mon, 27 Jan 2020 18:36:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lRXvwigmY44ilnTfpglLo9tXxwTel6n3jhHOqD2xkOZV4hJBWiJYpWbnovE+reJs43OGfvvMes0maHKNS5aHa6ssFTuAWNhniT8qtZQQ/I91eGEHOuVIqcKV8slsf2yJ/kb9v9X9Ju6S1ljQ0afpviQ2lSssPoWLYwG2gYnUsN57CEHq190udyxictfcLmGlPgy3dwE0MxFzzO9vwLIDWKXURDi0PdXsaapAbcK/GhqUSKkcWNrossGkufjnb1go1XmxhjS3XN9C3C6j2BO1MFrmL4QRhqcrvd5+KS16f8kQHotDLkRDsPngmjSbccxgmOfYLl52D8kgDFJMnrrQvg== 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=iULah4SsFpI9Lzr5ZQ8N8wtP8SeKD5k0Y5OQ9MmHD2E=; b=H1KxQmwku/+LdlD8KA7Fz8xUvE+9oFIPUuXYH4Gn8JGP4jmtyTO8A6AmvmW7X6Rdbfd8s5LomeEYq5efhITmkmu+rMqAi0MFlDt5uA9lu8DzRpGqMu51fgTcFwbkK/JoA0o8ygUAkSWKuSpmu7P/DM7U7nLupuaSqMpSbhTb5RAk1f9o5Mo4kkreOfpXQTzo9IVwy1f8pCiZeXW4rI1GKBWzlNWpVqfoIMh1EuTJE6nuWmKQ3HTzU2JVhopu0nCY2zU6w2kngS3McCBzy1IDz8go6WQd/PBEsi27zgx8Ou6q+dltM/TtMMgvGWGwDpUahVuMHzqSF8jZw44ugc7crg== 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=iULah4SsFpI9Lzr5ZQ8N8wtP8SeKD5k0Y5OQ9MmHD2E=; b=AHuXrw8hyEJDzGLlIth45gHNIwJiTfvl/BcT8z2FezyzviOjIhdr7ALJewQZe6zq1XOVXoM0XftyUo1BdueD1BMMuNWwLolUp49nyO8feVyVbYYv4J8kTe4o74vhFSCMMidZsH2SlmIHjqmz4gu45MwywsaEnJ0hSvxK6fPL+wK6zoKUPvMWRy/eX7mKbGzSyIeUKq+sxQIwiDrD8+QOAxHS1eJcvUG+/gbBKoHMvUZmQGDKyC3brsBAeQ5okM+bn4ewtKV8z8bgmiijgEqVgSpgSepjYxOA8Y3sHaQBCzFr9xPsCEdgRNXImLsSi7eJmRXqk4cE+LAtCxEvGM3m5w== Received: from DM6NAM10FT060.eop-nam10.prod.protection.outlook.com (10.13.152.52) by DM6NAM10HT235.eop-nam10.prod.protection.outlook.com (10.13.153.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2665.18; Tue, 28 Jan 2020 02:36:45 +0000 Received: from DM5PR07MB3067.namprd07.prod.outlook.com (10.13.152.54) by DM6NAM10FT060.mail.protection.outlook.com (10.13.152.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2665.18 via Frontend Transport; Tue, 28 Jan 2020 02:36:45 +0000 Received: from DM5PR07MB3067.namprd07.prod.outlook.com ([fe80::29e3:53bf:163e:5beb]) by DM5PR07MB3067.namprd07.prod.outlook.com ([fe80::29e3:53bf:163e:5beb%3]) with mapi id 15.20.2665.026; Tue, 28 Jan 2020 02:36:45 +0000 To: Nikita Popov CC: Claude Pache , Nicolas Grekas , Mark Randall , "internals@lists.php.net" Thread-Topic: [PHP-DEV] [RFC] "use global functions/consts" statement Thread-Index: AQHV1IfBuqjWnIu9lEWrxlRKvYFij6f9dXecgADKhQCAAFMdqIAACCeAgAC7crk= Date: Tue, 28 Jan 2020 02:36:45 +0000 Message-ID: References: , In-Reply-To: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:B39909EC6F230749E685928C74098497FC5ED7D47522983B3AA8C38D9C6AF6DF;UpperCasedChecksum:BF473117F1EAAFB166C6131DCEC4034553B0652B49F84655A8B3ED515CDB6BE8;SizeAsReceived:8396;Count:46 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [8a98MF0o7LfyXH0uuFK450vtdkRrVZ2z] x-ms-publictraffictype: Email x-incomingheadercount: 46 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 0f62bc5a-49f4-4389-9f69-08d7a39aea94 x-ms-traffictypediagnostic: DM6NAM10HT235: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: zwVS/Ms3eqSy4DxsXq/z2QPVlGGhsxZAjmwrZgGz3kebjdQ+G3I7/TAhGUA/lOc3xSIOsk1nyA7AgeFlgMmwiO0WP8w8+z6rQo9lGhTAur9aFI1nZQ8DzAxd9TIaeXNmZqc4J7mIhQkSgtpY76Or7bjcTxsu+hEyPRX1Ce42uHhWEaRa/2xSA6kbCkAZuBmZJlUDN7ylHJEiCnx7Ik336ZsD2n8I4MbJnc5hsyiTXCI= x-ms-exchange-antispam-messagedata: fxGqbfMc1jEu7E6LR4psnN8keX99AwagjL7LLuJQcdI0I8E8MrrHqKF6npOw1DvgEPWSmiFGDaaaU/dFTflT3XCt8tcDep3j9U9AVjGbJ7xKSX2HcO11jLaPHa2ZX4K2/KZB+FOBOYrVcvOruSY6KA== 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: 0f62bc5a-49f4-4389-9f69-08d7a39aea94 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Jan 2020 02:36:45.1164 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6NAM10HT235 Subject: Re: [PHP-DEV] [RFC] "use global functions/consts" statement From: tysonandre775@hotmail.com (tyson andre) https://wiki.php.net/rfc/use_global_elements#implementation_details has bee= n updated after the latest feedback.=0A= The implementation was also updated.=0A= =0A= The opt-in `declare(function_and_const_lookup=3D'global')` directive=0A= now only allows declaring a function or constant in a file if the same name= has been used=0A= in an above statement with `use function MyNS\function_name;` or `use const= MyNS\MY_CONSTANT`.=0A= If it was not used and the current namespace is not the global namespace, i= t is a compilation error.=0A= =0A= This is more verbose, but makes certain types of bugs impossible to write,= =0A= and guarantees that the function being declared is the one being referred t= o=0A= in subsequent uses in the same block of code (e.g. after/within the "namesp= ace MyNS" statement).=0A= =0A= Declarations of functions/constants are often in a few files that are separ= ate from other files,=0A= and there are several options to deal with the verbosity:=0A= =0A= 1. Use =3D'global', or don't enable function_and_const_lookup in those file= s.=0A= 2. Accept it and add all of the required uses=0A= 3. For constants, use define(). Not ideal, but still an option.=0A= =0A= I plan to move this to the voting phase on Tuesday if nothing else comes up= .=0A= =0A= As an example of how edge cases would work:=0A= =0A= ```=0A= declare(function_and_const_lookup=3D'global')=0A= namespace MyNS;=0A= // Outside the global namespace, without 'use function MyNS\my_function;',= =0A= // declaring a function is a compile error when function_and_const_lookup= =3D'global'.=0A= use function MyNS\factorial;=0A= use function MyNS\sprintf;=0A= use const MyNS\MY_PREFIX; // same for constants.=0A= =0A= const MY_PREFIX =3D 'Prefix';=0A= function sprintf($msg, ...$args) {=0A= // this forces the implementation to explicitly refer to sprintf from t= he global namespace.=0A= return \sprintf(MY_PREFIX . " $msg", ...$args);=0A= }=0A= function factorial(int $n) {=0A= return $n > 1 ? factorial($n - 1) * $n : 1;=0A= }=0A= if (version_compare(PHP_VERSION, '8.0.5') >=3D 0) {=0A= // ...=0A= }=0A= ```=0A= =0A= Thanks,=0A= - Tyson=