Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107878 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 98233 invoked from network); 28 Nov 2019 11:10:01 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 28 Nov 2019 11:10:01 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 3E0152C3E4E for ; Thu, 28 Nov 2019 01:05:08 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Thu, 28 Nov 2019 01:05:06 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id i12so30025642wrn.11 for ; Thu, 28 Nov 2019 01:05:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=beberlei-de.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=12m5hIHTq+xViNBPITfRNKsPlQ3UWogc/1hMArkEVTc=; b=TQGKCiBCS3biNnCLDK5FYUHp4CMH+Xw0K6N2O8S8UtyfyI4MU2h0nPvFzurkCSpV07 SGqkLB4imm9e1w9YE616dpU7wOhHeyatLNZ4vCncmMCusJ/rxQRtU6thlmp02h37sT+z /UmJ3D1hEPkqQmESBQ9XN1G0IMMYJkW3Ejnj3jDqbZXu+C/EYlsMJndZw0zRN9kZOlQG IiPZlg/nw97KFnFnWMFFOJqodkUU9PyD5DHCWQAdOo+LtKG2TrsoZrF4TdER86Xs2fLb PTKWd8Y8H9DzDDUYp4tUQG3dfHGBtssixGweTdihZtpd4Gh8i9C//Ba2L4wsfGjIMfnC 9+5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=12m5hIHTq+xViNBPITfRNKsPlQ3UWogc/1hMArkEVTc=; b=igZ9hHRWduIvWvrlVX5OBpgT7FJMJiw9bu+eFAUFc+8JHylc+XkFd4JtBUnumBF+fB FsLFHJ9VA8Pozk+UYlT4uHzFMyyZqJMy879+ox+3+IFH2Aomc10Y7mNNkQ9SQU2w+c0U BACIwpsG3uZ4JFKLrY0rbASRmDIsUbPzIl+2z7/kT1xI+Cvx4HWmIT73V46mB4AHhAHA 8t3/pDh6uXyUFaOJLrER5w0FIPv5at05XV5Yl/PtMsx4mpyJWTOOnaCKC4mnX9pEcYXW tXCL2ro047raKOvju1ZijFNq6pXVTESBzou5Mm7qs3yU6bhStyRnl8nO/LDWreVVrgG8 IP9Q== X-Gm-Message-State: APjAAAVWzNA8A6giAAy/x58eyHgWo5rVNHYqwtYM+8DMp966Yn357SOe mrld3Gh0OpFu2av775jp1i60qAWOJdW9vLixiCRC5A== X-Google-Smtp-Source: APXvYqxeZ6ni3fhJdJlhz4GRNJFvKwb3P5usgRi0/rsuNXA/TQyyoUFbRuvRD8MK20PQSwPaiXvXe9mkCw7mglzdAEU= X-Received: by 2002:a5d:608a:: with SMTP id w10mr6741722wrt.136.1574931905904; Thu, 28 Nov 2019 01:05:05 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 28 Nov 2019 10:04:53 +0100 Message-ID: To: tyson andre Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary="000000000000cc1b57059864685e" X-Envelope-From: Subject: Re: [PHP-DEV] Opt-in "use function *;" for skipping check for function/const in alternate namespace From: kontakt@beberlei.de (Benjamin Eberlei) --000000000000cc1b57059864685e Content-Type: text/plain; charset="UTF-8" On Thu, Nov 28, 2019 at 1:02 AM tyson andre wrote: > > What are your thoughts about syntax such as the following, similar to the > syntax for Java (only for use of functions/constants from the root scope) > > namespace My\NS; > use function *; > use const *; > // can use functions/constants from namespaces that aren't the global > namespace to override '*' > // "use *" is not valid. > printf("PHP Version is: %s\n", PHP_VERSION); > > I love the idea. it is a small detail that needs fixing, especially since more and more open source libraries start to import *all* internal functions they use (which I personally find quite ugly) to get the small perf boost. > A similar opt-in directive syntax "use function root;" was mentioned as an > alternative to the "Deprecation of fallback to root scope" RFC > https://marc.info/?l=php-internals&m=151788196501507&w=2 . (I couldn't > find any other mentions after a quick search) > > Benefits of "use function *": > - Visually cleaner and less prone to merge conflicts than "use" for dozens > of functions/constants all from the root scope. (or writing \printf("PHP > Version is: %s\n", \PHP_VERSION), or mixes of the above) > - Due to the absence of function autoloading (not supported in php to > performance overhead), functions outside the global scope are rare in > practice. > - This would make it easier to make edits to a project (if the project's > code style involves the unambiguous use of functions/global constants) > - This makes using unambiguous functions/global constants easier. (for a > small performance boost due to the php interpreter not needing to check > both namespaces, opcache knowing exactly which function/constant it is, etc) > - Does not break third-party code > > The other RFC https://wiki.php.net/rfc/fallback-to-root-scope-deprecation > had the following notable objections, and I'm not sure of the current > status of it: > > - Deprecating the behavior of existing code would break (possibly > unmaintained) third-party libraries and require a lot of code changes, > discouraging updates > > "use function *;" wouldn't. > - Some mocking libraries will declare functions in namespaces being > tested, with the same name as the global function. > My proposal has similar drawbacks - third party code that started using > "use function *" would break those libraries (but so would manually adding > the same namespace uses). > > But there are alternatives to those libraries, such as uopz, runkit7, > and SoftMocks (SoftMocks changes the class autoloader to replace code with > instrumented code). > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --000000000000cc1b57059864685e--