Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107881 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 23983 invoked from network); 28 Nov 2019 12:22:47 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 28 Nov 2019 12:22:47 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 182092D1FE8 for ; Thu, 28 Nov 2019 02:17:55 -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=0.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MALFORMED_FREEMAIL, MISSING_HEADERS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) (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 02:17:51 -0800 (PST) Received: by mail-oi1-x236.google.com with SMTP id 128so14809538oih.4 for ; Thu, 28 Nov 2019 02:17:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:cc; bh=EWi8/em93Ex3VREd9kgXGOXtllFdnxLWrVxqFfzzNDQ=; b=LUuI3J+RZ74mHwZcdPXKWrdxaegmH5xWH6ZAfLh6qySUJJcf85nEKe8ko1iuieTSgC PTILU5/+9uiKltavMWl8l71OAoJEy9M8/2Pob39xwk2HdwjfTQOsS0ONbrnd9zJw5vua O/NsjUDSaVNDxYD8fA0cdEyfjadRECwC5WAscwqs4+azIz1JML2Cgwe4xhRurCL0yStX TWdllwE/TBlrX3hA5Rq4slOCamywtMuy0YRMwS/ijIrmRNxDdXHPA7DmjFki46j1WPdo ql6z5biRaeNYPz1JsHchOrzsjilbWL+mcFW24hWOieSi9UlhT38Kne3Zw8zeV7efCYXd X1LA== 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:cc; bh=EWi8/em93Ex3VREd9kgXGOXtllFdnxLWrVxqFfzzNDQ=; b=oLB5Y3goObW1fSmROcZZVlU57+IclL+ACRdGflUkYka9NE7EzG1uZC07wndsFUa+X2 ZkDuZx345P3vO4C6Ptx1OOCaHkUytSHsJGgH1NsHTtwaO1RdgkvnX0ogFMPGTJxEkA8c O9RedKPFBrloZmZMwyM+1TcZRHceC0tKfidOB8E6SvpqNIXzupVzJLZUlXpUKEI+Bo2y 6nHAP057gSWDpQlnbxuNjfC80q7l0U0lE58gddCRRRapfI9+qQ7COLLrt8ibTuSj/ZII FkbrR9i0eyTW5maLKYFh8/Ah374F4V8LEXq4WWGikgpDipxxRKRZqfwfYoloc4uVucGg ZP2g== X-Gm-Message-State: APjAAAXbq2yEf9wBmUTynhnTbqavH0Sw00u75zcnzXt61QabjOJoo5p4 x+pS0dwvlfrAEiu2pr0gPH+QuXS9r5kLFYir5FqpzRvk X-Google-Smtp-Source: APXvYqzSRFZhFu+FBCdGoPnIGdW95Jibq1F1C3wDp8J4WtNQ3O0s0rJlSEQ4IwNKTMc5TkToFiBQHDVTZOX/HFY1AuU= X-Received: by 2002:a54:478f:: with SMTP id o15mr8191296oic.34.1574936270839; Thu, 28 Nov 2019 02:17:50 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 28 Nov 2019 10:17:39 +0000 Message-ID: Cc: "internals@lists.php.net" Content-Type: text/plain; charset="UTF-8" X-Envelope-From: Subject: Re: [PHP-DEV] Opt-in "use function *;" for skipping check for function/const in alternate namespace From: robehickman@gmail.com (Robert Hickman) > > 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 am in support of this, and my personal code still doesn't use namespaces at all due to things like this, relating to the handling of functions in the language. I personally think that the whole 'autoloading' concept is a bad idea, and ahead of time import and compilation to bytecode, as offered by preloading is a far better idea. On Thu, 28 Nov 2019 at 00:02, 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); > > 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 >