Skip to content

Completely remove disabled functions from function table #5473

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

Closed
wants to merge 3 commits into from

Conversation

nikic
Copy link
Member

@nikic nikic commented Apr 27, 2020

Currently, disabling a function only replaces the internal function handler with one that throws a warning, and a few places in the engine special-case such functions, such as function_exists. This leaves us with a Schrödinger's function, which both does not exist (function_exists returns false) and does exist (you cannot define a function with the same name). In particular, this prevents the implementation of robust polyfills, as reported in https://bugs.php.net/bug.php?id=79382:

if (!function_exists('getallheaders')) {
    function getallheaders(...) { ... }
}

If getallheaders() is a disabled function, this code will break.

I don't think it is possible to reconcile this. Making function_exists() return true would fix this case, but would break other cases, that check function_exists() before calling a function.

I think the only way to make this fully consistent is to actually remove the function from the function table. I don't think this has any disadvantages, apart from throwing a more generic error message.

This will make the ReflectionFunction::isDisabled() method useless, as it will no longer be possible to create a ReflectionFunction of a disabled function. Similarly, the $exclude_disabled parameter of get_defined_functions() will be hardcoded to true.

@cmb69
Copy link
Member

cmb69 commented Apr 27, 2020

Thanks, I like that very much. Should disable_classes be treated in a similar manner (see also https://bugs.php.net/79516).

@nikic
Copy link
Member Author

nikic commented Apr 27, 2020

Thanks, I like that very much. Should disable_classes be treated in a similar manner (see also https://bugs.php.net/79516).

I agree, but the class case will probably have some complications, because we often reference class entries internally. We must make sure that the class entry is not destroyed.

@staabm
Copy link
Contributor

staabm commented Apr 29, 2020

should ini_get('disable_functions') return a empty value and emit a deprecation warning in case this change gets merged?

@nikic
Copy link
Member Author

nikic commented Apr 29, 2020

@staabm Why? ini_get() should return the value it has been set to, as usual.

@staabm
Copy link
Contributor

staabm commented Apr 29, 2020

oh, then I misread the PR. had the impression the disabled-function mechnics will be removed.

fine then.

@nikic nikic changed the title Completely remove disabled functions Completely remove disabled functions from function table Apr 29, 2020
@nikic
Copy link
Member Author

nikic commented Apr 29, 2020

@staabm Ooh, yes, I can see where that came from :) Renamed to be a bit more obvious.

@php-pulls php-pulls closed this in 53eee29 Apr 30, 2020
nicolas-grekas added a commit to symfony/symfony that referenced this pull request May 23, 2020
… (derrabus)

This PR was merged into the 3.4 branch.

Discussion
----------

[VarDumper] ReflectionFunction::isDisabled() is deprecated

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | #36872
| License       | MIT
| Doc PR        | N/A

See php/php-src#5473. Calling `ReflectionFunction::isDisabled()` is pointless on php 8 and doing so triggers a deprecation warning.

Someone who is more familiar with that component might want to have a second look on this PR. I'm not really sure if this is the right way to fix the issue.

Commits
-------

1da347e [VarDumper] ReflectionFunction::isDisabled() is deprecated.
@carusogabriel carusogabriel added this to the PHP 8.0 milestone May 29, 2020
jrfnl added a commit to PHPCompatibility/PHPCompatibility that referenced this pull request Jun 29, 2020
…ctionsExcludeDisabledFalse` sniff

> Calling `get_defined_functions()` with `$exclude_disabled` explicitly set to
>  `false` is deprecated. `get_defined_functions()` will never include disabled functions.

Refs:
* https://github.com/php/php-src/blob/69888c3ff1f2301ead8e37b23ff8481d475e29d2/UPGRADING#L514-L516
* php/php-src#5473
* php/php-src@53eee29

This sniff addresses that change.

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

Successfully merging this pull request may close these issues.

4 participants