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
Add a rule to root-namespace special compiled PHP functions #3048
Comments
I was just about to raise this. you beat me to it :) |
btw, this is already covered by the but as you said, it could have extra configuration to only replace the function calls you link to. |
looks like a nice scenario |
IIUC |
@SpacePossum correct, |
haha, next scenario when it's always better to use strict comparisons ;) |
is there anything left for this fixer ? |
For the purpose of Symfony, I may advocate that a rule that enforces the backslash when it provides something substential should be enabled. |
I have a branch that will provide what you are after, however it is built upon the one linked PR, the linked PR itself does not. |
Cool, thanks for doing the hard work on this. |
@nicolas-grekas , what about later part?
|
@keradus not sure what you mean? If you mean devs should be required to always add the backslash prefix, I certainly don't agree, there is zero perf benefit doing so, but only more visual debt in the code... |
I'm saying that there is benefit, as if you add |
Did you try measuring it actually? Last time I did, I couldn't spot any difference at all, except for the specific functions listed above. |
|
If it does make a difference for all calls:
Why can't this be a different issue report so the same discussion is not done two times, here and in the PR? This issue is about a special subset of native calls, the PR about scoping the namespacing, I don't see the need to widen the scope. |
it does, like
As in scope of file, we are unaware of all user-defined functions :( we know for sure that native functions are defined in root scope and hope they are not overwritten in namespace (which could be in different file). We cannot be sure that user-defined function is declared in root scope.
For sure it's worth to not work on it twice, yet before implementing I want to be sure this part it's needed (configuring to fix only subset). Thus I took discussion-first approach. |
On the very first call, opcache resolves the namespace once for all and replaces the slower opcode by the fully qualified one. This hot replacement is free compared to running whatever the rest of the code does. |
you see, it's not hard to discuss ;) |
@keradus ?????? |
what's up? |
There is the [
'native_function_invocation' => [
'exclude' => [],
'opcache-only' => true,
]
] That would be forward compatible with version 3. |
or add an |
Since PHP 7.0, some functions are replaced by opcodes, producing much faster code. Yet, for this to work, these functions need to be referenced in the root namespace at compile time: Either there is no namespace, or they are prefixed by a \. If accepted my plan is to do this for each component one at a time (easier to review) Reference PHP-CS-Fixer/PHP-CS-Fixer#3048
Since PHP 7.0, some functions are replaced by opcodes, producing much faster code.
Yet, for this to work, these functions need to be referenced in the root namespace at compile time:
Either there is no namespace, or they are prefixed by a
\
.php-cs-fixer should have a rule to list those functions and enforce adding this
\
when used inside a namespaced file/class.Here is the exact list of functions that have this behavior:
https://github.com/php/php-src/blob/f2db305fa4e9bd7d04d567822687ec714aedcdb5/Zend/zend_compile.c#L3872
(don't miss #3048 (comment))
The text was updated successfully, but these errors were encountered: