-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Change the way built-in functions are resolved #13632
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
Comments
See prior discussion on this subject |
I haven't followed this discussion, so I'm not sure why this RFC failed. I can think of two basic approaches:
So, given these caveats, I'm not sure if there's a good way to proceed. |
There has not been any recent activity in this feature request. It will automatically be closed in 14 days if no further action is taken. Please see https://github.com/probot/stale#is-closing-stale-issues-really-a-good-idea to understand why we auto-close stale feature requests. |
OK, let's close this proposal because it didn't have any recent activity. I'll try to keep sending other ideas in the future. Cheers! |
@javiereguiluz I agree that it would be great transitioning towards statically known namespaces for function calls. In practice, I'm not sure how to best achieve it without lots of code churn. A Also, it's quite annoying that the chosen approach for functions would be the opposite of the one chosen for classes (global by default for functions, local by default for classes). Disambiguating local functions is also a bit ugly (e.g. I suppose another approach could be to just reverse the lookup order: If the function exists globally, use that. Otherwise, use the local function. This should result in much fewer code changes, while allowing static knowledge of internal function calls, which are the majority of all non-instance function calls in OOP code bases. WDYT? I will have a look soon to see if this makes a meaningful difference in a few code bases. |
I created a simple PoC here: iluuu1994#132 It results in a 0.91% reduction in instructions for Symfony Demo. But it's unclear how much that correlates to performance. I will measure real time next. |
I wrote a script to analyze the impact by checking how many namespaced functions exist in the top 1000 composer packages with names equivalent to internal, global functions. https://gist.github.com/iluuu1994/4b83481baac563f8f0d3204c697c5551 There are 484, with the vast majority coming from |
Let's close this issue because the related PR #14529 was closed as "won't fix". Thanks! |
@javiereguiluz There is some hope for this still. @arnaud-lb is thinking about the concept of modules, which is a collection of files compiled at once, reserving some namespace for itself. If during compilation it is evident that some local function (e.g. |
Description
When some PHP app uses a function like
file_exists()
, the PHP compiler doesn't know if it's the PHP built-in function or a user-defined function added by that project.This has some impact with changes like this: #12461
To unlock the potential performance improvements of that PR, you have two options:
(1) Prefix all calls to PHP built-in functions with
\
(2) Import all PHP built-in functions with
use function ...
Both solutions look cumbersome to me.
In other words:
substr()
orfile_exists()
and PHP needs to take that into accountCould PHP fix this in some way? Here are some proposals:
(1) We could make this behavior opt-in instead of opt-out. If a project includes user-defined functions that match built-in function names, make them add a
declares(overrides_php_functions=1);
statement(2) In order to change the default behavior in a backward-compatible way, we could add a transitory
php.ini
directive such asoverrides_php_functions
set totrue
by default (to match current PHP behavior) and then apps can change it tofalse
so the performance improvement can be unlocked without changing their codebaseThanks
The text was updated successfully, but these errors were encountered: