Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107957 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 34962 invoked from network); 2 Jan 2020 07:33:35 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Jan 2020 07:33:35 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 476DE180505 for ; Wed, 1 Jan 2020 21:37:25 -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 NAM02-SN1-obe.outbound.protection.outlook.com (mail-oln040092005093.outbound.protection.outlook.com [40.92.5.93]) (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 ; Wed, 1 Jan 2020 21:37:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TNlIbFduaOKTlYwpPvvi4H9uBBZrQMXegTSx22Blr2SqVRHC3dBwCenlf8eyd5LchnnJP35s8RSPn3abPS9nUWRlSmVzMw8syXpPCZA+JnfkVb+KGfnGigGgBPY1JhHJ2kqWnmiON9AeMdloAvwHDorpCVWNFT1cTtQGXpDHX4L2f9PSOJOJRNwJPJBkbRIs4vgYswDhBfkkYfMsZ4b/QnUDEBDaWXxBqJNpJO76pQgYc4B6jZDT8o0y/2RrhBMuidq8ZPC3DabGXLETODCFxAZoK+EfMV5tXWtbuYA1OlbzgvJsQiap2H2JLOEJiHtK0wkB+3sbvqVNaDccxq9W0g== 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=lJrqMC38Zzv7G5LDrHQxorlnjyboxyN4wPQzRL0/caw=; b=V3BkuPGD7gn9gPd7RlaD9fV8D57U9USCXoL+Jt2F3JaX0fEfHw1IQD+E5tmU34URa1ktJNrbZgJkVlJQ0idgjwKSiQfPn7oalLt1WA3DAke1M8fVKEdozbkmp0IObwbnHvY+I7tgmZYkLfbBOGjQNT1K/gS6cYY5w7LSCVROW/BiHNcZJyzP2mZ21qJWfkTK4V3kPJvGhQLFYhSsg8DgQJozi9XcI7uKjqYB4S75MWh79i3HngPYon+3xBKEKqMc+rqjne1hm8n40vsfVoqbDAaity/NTLv6LmCryT3p3Hi8vxM/XVuQN4t9wtZEWEYgPcBbwk1oi20dD+ov9s2eRg== 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=lJrqMC38Zzv7G5LDrHQxorlnjyboxyN4wPQzRL0/caw=; b=qfW/OJmRzjRXYP38WveEvpDeUbAeoI5q9xLBY/gM7m5CiJ/j61BRO9VQXwzuvxx5Meob52afTO/vTepe8yiMBgKe92nzXT+URT61Waqm5Xk0Ugrfk1FZC0I4AKWKTnZf9aC9/uMWFbMHRoN07+tvKSOzkQ6wEDMmSPKj3Dzsu2Hh7XVzINzEplJghpHXondUiiptGVntWNgAlUBNqPrkvHWQN4OAlBoiSFhksDZMwPd1LEhSEaNJvoaFN2qqHiVeSDkRRNAA1iSJJrCiUuoJB5R6oLcXXzy7x0lkMjDGlF94zr843VkDbgUmkUJLbWG4xkmvDCr9FyMJwiNEqsEAZA== Received: from SN1NAM02FT038.eop-nam02.prod.protection.outlook.com (10.152.72.59) by SN1NAM02HT195.eop-nam02.prod.protection.outlook.com (10.152.73.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2602.11; Thu, 2 Jan 2020 05:37:22 +0000 Received: from DM5PR07MB3067.namprd07.prod.outlook.com (10.152.72.59) by SN1NAM02FT038.mail.protection.outlook.com (10.152.72.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2602.11 via Frontend Transport; Thu, 2 Jan 2020 05:37:22 +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.2602.012; Thu, 2 Jan 2020 05:37:22 +0000 To: Mark Randall , "internals@lists.php.net" Thread-Topic: [PHP-DEV] Re: [RFC] "use global functions/consts" statement Thread-Index: AQHVwNgGtev425C1jEaW2/fYCDQJoKfWyWcAgAABfxQ= Date: Thu, 2 Jan 2020 05:37:21 +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:354462E283211F19A4C48B1262B02DA749E2BFAFA7E6FBF1E2E4CDA43284929A;UpperCasedChecksum:0263151A4E894CBBE96F25F7EBC05B2BC57133C8CF9A0C1D1E8554FAE2AE70BB;SizeAsReceived:7286;Count:45 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [xz6vzP0xHySgf44Hos03buZHeybkldSzkFC4jwKWCVWmn2/Yb7z82qX0/6a4XUKW] x-ms-publictraffictype: Email x-incomingheadercount: 45 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: f8169f43-21f9-42e9-b956-08d78f45d713 x-ms-traffictypediagnostic: SN1NAM02HT195: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Vr0DCqcBJRsF4dkryuYjqxEa9d5rgIrPj+pC98wE1BQALoPpo+PZG9UObqfn3EzkjFioZI+tncWduAOvTgiyoxzJw62Os8lwDmTfPrEcVh661MMLy8Wb9R75t1B6nyt//dZNOeCPLpj/noMVc9lcMsSTRzWsT89VD1/KmAU62T9s7DmM9rDUwnGQCwNIQADd 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: f8169f43-21f9-42e9-b956-08d78f45d713 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Jan 2020 05:37:21.9619 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1NAM02HT195 Subject: Re: [PHP-DEV] Re: [RFC] "use global functions/consts" statement From: tysonandre775@hotmail.com (tyson andre) > It's an interesting idea, but at this time I think it's the wrong =0A= > approach to what is in the best long-term interests of the language by = =0A= > introducing an additional point of inconsistency.=0A= > =0A= > Classes search the current namespace, but functions / const would search = =0A= > namespace first, unless they don't, then global?=0A= =0A= Assuming you mean "unless they don't" is the additional inconsistency:=0A= =0A= I still see this as a cleaner/less verbose option than the currently availa= ble options=0A= for avoiding ambiguity - aliases add similar resolution behavior.=0A= =0A= "function_name() will search the current namespace first,=0A= then the global namespace,=0A= unless "use function [.... as] function_name" was found=0A= earlier in the namespace block."=0A= =0A= > For the very minor one-time performance hit (thanks to the cache slot), = =0A= > I think the situation is best remaining as-is for the time being.=0A= =0A= That was unintuitive to me -- but it is one-time.=0A= (ignoring optimizations of specialized opcodes=0A= and inlining results as constants)=0A= Running the following example outputs "Length is 4" twice.=0A= =0A= In future, I think the optimal solution is opt-in deprecating fallback = =0A= > to the root namespace using a declare.=0A= > ... Id like to see nikic/scalar_objects added to the core in 8.0=0A= =0A= Various global functions (strlen(), count(), class_exists(), is_string(), e= tc.)=0A= are more frequently used than namespaced functions in many files,=0A= and removing the fallback *to* the global scope would break most third part= y code,=0A= which might be unmaintained.=0A= This backwards compatibility break would discourage upgrading=0A= to future major versions.=0A= =0A= > That doesn't cover defined constants, but IMO we should be pushing those = =0A= > to be moved into class constants, simply because in the absense of =0A= > function / constant / anything-but-class level autoloading, things might = =0A= > as well be in a readily available location.=0A= =0A= Out of scope of this RFC: I had a thought today about autoloading.=0A= I'd rather improve function / const autoloading instead of moving to classe= s. =0A= What if an ambiguous function_name() or const outside the global =0A= namespace would attempt to autoload *ambiguous* functions in the global sco= pe,=0A= but not the current namespace?=0A= (and autoload unambiguous functions in their respective scope)=0A= function_exists() or defined() would not autoload,=0A= to preserve the behavior/performance of current programs.=0A= Anything with the callable type hint (e.g. array_map) would also need to be= modified.=0A= =0A= - Same for global constants=0A= - That should avoid the performance hit - this autoloading would only be tr= iggered=0A= when php would previously throw an Error or warning=0A= for undefined functions/constants.=0A= - This would also avoid the need to load polyfill files (e.g. mbstring)=0A= or test framework files when their functions/constants are unused.=0A= - The main blocker for other autoload proposals=0A= seemed to be performance if I understood correctly=0A= (e.g. attempting to autoload NS\strlen() every time strlen was called)=0A= =0A= Fully-qualified calls (through use, \, or being in the global scope) would= =0A= autoload the unambiguous name for missing functions.=0A= =0A= And there'd have to be a hash map or other check=0A= to avoid recursion on the same constant/function.=