Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Namespace internal functions and constants #6807

Closed
michsk opened this issue Nov 2, 2017 · 9 comments
Closed

Feature request: Namespace internal functions and constants #6807

michsk opened this issue Nov 2, 2017 · 9 comments
Assignees

Comments

@michsk
Copy link

michsk commented Nov 2, 2017

Couldn't find any other issue mentioning it. If interested i could make a pull request. There are multiple tools to achieve this:

https://github.com/nilportugues/php-backslasher
https://github.com/Roave/FunctionFQNReplacer
https://github.com/kelunik/fqn-check
https://github.com/FriendsOfPHP/PHP-CS-Fixer (native_function_invocation )

@lcobucci lcobucci changed the title Feature request: Namespace interal functions and constants Feature request: Namespace internal functions and constants Nov 26, 2017
@lcobucci lcobucci added this to the 3.0 milestone Nov 26, 2017
@Majkl578
Copy link
Contributor

Majkl578 commented Dec 9, 2017

I'm personally not convinced this is a good approach, it makes code much harder to read... I'd be +1 only if there is noticeable speedup at runtime which I doubt this would bring. 😕

@Ocramius
Copy link
Member

@Majkl578 a better approach is to import them via use function foo; - simple and same effects.

@Majkl578
Copy link
Contributor

Majkl578 commented Jan 1, 2018

If we want to do this, we can use SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions for CS enforcement, but it currently sees no difference between \ and use function - if we only want one (use function), we need to extend it a bit.
Also be aware that this approach could easily end up with 20+ use statements for functions (typically collapsed by IDE, but still).

@Ocramius
Copy link
Member

Ocramius commented Jan 1, 2018 via email

@Majkl578
Copy link
Contributor

Majkl578 commented Jan 3, 2018

Provided CS sniff extension for enforcing use function/use const in slevomat/coding-standard#235. (moved to slevomat/coding-standard#236) I guess it now depends on IDE (PhpStorm assumed) how clever it would be when handling this. Will try later and eventually propose this for doctrine/coding-standard.

@Majkl578
Copy link
Contributor

Majkl578 commented Jan 3, 2018

Checked PhpStorm, looks it can handle it as fine as classes.
options

@Majkl578
Copy link
Contributor

Majkl578 commented Jan 8, 2018

I prepared this in doctrine/coding-standard@15968c3, example of how noisy it'd be is here: Majkl578@2b69bd9
I also tested PHP with VLD with multiple scenarios and didn't find any drawback of using use rather than \ - functions were correctly inlined and/or specialized to custom opcodes, even aliased ones. https://3v4l.org/YiCjS/vld#output

@Majkl578
Copy link
Contributor

This has already been done in master. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants