Re: [VOTE] declare(function_and_const_lookup='global')

From: Date: Wed, 29 Jan 2020 04:03:21 +0000
Subject: Re: [VOTE] declare(function_and_const_lookup='global')
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-108307@lists.php.net to get a copy of this message
On Tue, Jan 28, 2020 at 8:22 PM tyson andre <tysonandre775@hotmail.com> wrote: > Hi internals, > > I've opened the vote on > https://wiki.php.net/rfc/use_global_elements Thank you for working to address the issue of ambiguous function references.. However, I really don't think this is the right approach. The RFC mentions two problems it hopes to solve: a minor performance decrease, and developers having to deal with ambiguity. However, a third problem that I think is just as important to fix is the lack of function autoloading which makes extensive use of namespaced functions unfeasible. Unfortunately, the new directive proposed by this RFC would make declaring functions in namespaces even more difficult, as it would now be necessary to explicitly use each function and constant in the same file it is declared in. The RFC argues that having to "add multiple use function function_name and use const MY_CONST at the top of the namespace" is prone to merge conflicts and inconvenient to keep up to date. However, the RFC just shifts this problem from global functions to namespaced functions. Changing function/const resolution to always look in the global scope instead of current namespace is backwards from how classes and interfaces are resolved, and seems destined to become another language Sadness. Wouldn't it be more straightforward and intuitive to add a directive like declare(namespace_lookup=1) which would resolve functions/consts the same way as classes (without the global fallback)? The RFC argues that writing global functions as \function_name() is more verbose. But is one backslash character per global function call any more verbose than having to add a 44-character declare statement at the top of every file? Developers are already used to referencing global classes and functions with backslashes or explicit use statements, and in a future where we have function autoloading and utilize more namespaced functions, this approach will be less verbose than having to explicitly use every namespaced function in the same file it is declared in. Plus, IDEs and other tools can automatically add the backslashes or use statements for global functions. Best regards, Theodore

« previous php.internals (#108307) next »