Feature request: Namespace internal functions and constants #5757

Closed
opened 2026-01-22 15:16:49 +01:00 by admin · 9 comments
Owner

Originally created by @michsk on GitHub (Nov 2, 2017).

Originally assigned to: @Majkl578 on GitHub.

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 )

Originally created by @michsk on GitHub (Nov 2, 2017). Originally assigned to: @Majkl578 on GitHub. 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 )
admin added the Improvement label 2026-01-22 15:16:49 +01:00
admin closed this issue 2026-01-22 15:16:50 +01:00
Author
Owner

@Majkl578 commented on GitHub (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. 😕

@Majkl578 commented on GitHub (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. 😕
Author
Owner
@michsk commented on GitHub (Dec 11, 2017): - https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/3048#issuecomment-330099642 - http://veewee.github.io/blog/optimizing-php-performance-by-fq-function-calls/
Author
Owner

@Ocramius commented on GitHub (Dec 11, 2017):

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

@Ocramius commented on GitHub (Dec 11, 2017): @Majkl578 a better approach is to import them via `use function foo;` - simple and same effects.
Author
Owner

@Majkl578 commented on GitHub (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).

@Majkl578 commented on GitHub (Jan 1, 2018): If we want to do this, we can use [`SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions`](https://github.com/slevomat/coding-standard#slevomatcodingstandardnamespacesfullyqualifiedglobalconstants) 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).
Author
Owner

@Ocramius commented on GitHub (Jan 1, 2018):

Not worried by amount of imports: better than inline diffs by far, plus we
can grep it if we ever need to get rid of something bad coming from core.

On 1 Jan 2018 23:44, "Michael Moravec" notifications@github.com wrote:

If we want to do this, we can use SlevomatCodingStandard.Namespaces.
FullyQualifiedGlobalFunctions
https://github.com/slevomat/coding-standard#slevomatcodingstandardnamespacesfullyqualifiedglobalconstants
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).


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/doctrine/doctrine2/issues/6807#issuecomment-354682318,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAJakMvRqbMXJaSeZ0lWNQ1kimM1rWGmks5tGV_ggaJpZM4QPTFv
.

@Ocramius commented on GitHub (Jan 1, 2018): Not worried by amount of imports: better than inline diffs by far, plus we can grep it if we ever need to get rid of something bad coming from core. On 1 Jan 2018 23:44, "Michael Moravec" <notifications@github.com> wrote: > If we want to do this, we can use SlevomatCodingStandard.Namespaces. > FullyQualifiedGlobalFunctions > <https://github.com/slevomat/coding-standard#slevomatcodingstandardnamespacesfullyqualifiedglobalconstants> > 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). > > — > You are receiving this because you commented. > Reply to this email directly, view it on GitHub > <https://github.com/doctrine/doctrine2/issues/6807#issuecomment-354682318>, > or mute the thread > <https://github.com/notifications/unsubscribe-auth/AAJakMvRqbMXJaSeZ0lWNQ1kimM1rWGmks5tGV_ggaJpZM4QPTFv> > . >
Author
Owner

@Majkl578 commented on GitHub (Jan 3, 2018):

Provided CS sniff extension for enforcing use function/use const in slevomat/coding-standard#235. (moved to https://github.com/slevomat/coding-standard/issues/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 commented on GitHub (Jan 3, 2018): ~Provided CS sniff extension for enforcing `use function`/`use const` in slevomat/coding-standard#235.~ (_moved to https://github.com/slevomat/coding-standard/issues/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.
Author
Owner

@Majkl578 commented on GitHub (Jan 3, 2018):

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

@Majkl578 commented on GitHub (Jan 3, 2018): Checked PhpStorm, looks it can handle it as fine as classes. ![options](https://user-images.githubusercontent.com/144181/34536996-44635bce-f0c7-11e7-8c8f-5ab4235cb2ca.png)
Author
Owner

@Majkl578 commented on GitHub (Jan 8, 2018):

I prepared this in 15968c3495, example of how noisy it'd be is here: 2b69bd9594
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 commented on GitHub (Jan 8, 2018): I prepared this in https://github.com/doctrine/coding-standard/commit/15968c3495c4a5268edd2bd9bceb9264f67b1620, example of how noisy it'd be is here: https://github.com/Majkl578/doctrine2/commit/2b69bd95941308539b43fcbcaae9a272666c4233 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
Author
Owner

@Majkl578 commented on GitHub (Apr 12, 2018):

This has already been done in master. :)

@Majkl578 commented on GitHub (Apr 12, 2018): This has already been done in master. :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5757