Skip to content

Fix bug #31875 - get_defined_functions() should not list disabled fun… #1312

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

Conversation

willianveiga
Copy link

…ctions.

@Tyrael
Copy link
Contributor

Tyrael commented May 30, 2015

Why it is better to not list them?

@Majkl578
Copy link
Contributor

Why it is better to not list them?

function_exists returns FALSE for disabled functions.

@laruence
Copy link
Member

I don't think this is bug, or something worth to be fixed...

it's defined, just disabled..

@grangeway
Copy link

In 2005 when I first created this bug, I think I'd been trying to do some testing of php - and had knocked up a script to do foreach(function) { test } and/or was trying to develop against a locked down hosting companies version of php, and wanted to work out what functions were not available.

At the moment, as far as i'm aware, get_defined_functions() is still the only way in php to get a "complete" list of available functions. I'd personally say the expectation for someone calling this function would be that the function would work if it is defined. Otherwise you effectively need to create a get_available_functions ( foreach x in get_defined_functions( if function_exists(x)... for the output to be of any use.

@laruence In terms of the "it's defined, just disabled" argument - I think if PHP is compiled with --without-X, that functions belonging to X would not be included in the list of defined functions. Taking your comment to the extreme - if a function is defined, but not compiled in, then it's "just disabled" ;)

get_defined_functions — Returns an array of all defined functions
function_exists - Checks the list of defined functions, both built-in (internal) and user-defined, for function_name.

I'd expect that given the documentation, the result to be the same for the above functions.

However, the notes section on http://php.net/function_exists is confusing: "A function name may exist even if the function itself is unusable due to configuration or compiling options " - is that really the case?? Especially given the example given - to check if imap_open exists to test if IMAP functionality is in PHP. The return statement of RETURN_BOOL(func && (func->type != ZEND_INTERNAL_FUNCTION || func->internal_function.handler != zif_display_disabled_function)); would seem to be designed to negate the need for this comment?

@haskellcamargo
Copy link

Disabled functions yet are defined functions. I don't believe this is really a bug. Maybe we can have a get_enabled_functions, but not breaking get_defined_functions.

@willianveiga
Copy link
Author

Or maybe we could have a get_disabled_functions and let users do whatever they want with it in userland code.

@lubosdz
Copy link

lubosdz commented Jun 1, 2015

What about introducing extra argument:
get_defined_functions([exclude_disabled = true])
(Default settings would match current behaviour.)

@jpauli
Copy link
Member

jpauli commented Jun 4, 2015

@lubosdz I like it 👍

php-pulls pushed a commit that referenced this pull request Jan 4, 2017
* pull-request/1312:
  get_defined_functions extra parameter to exclude disabled functions
  news entry for PR #1312
php-pulls pushed a commit that referenced this pull request Jan 4, 2017
* PHP-7.0:
  get_defined_functions additional parameter to exclude disabled functions
  news entry for PR #1312
@krakjoe
Copy link
Member

krakjoe commented Jan 4, 2017

Merged d838285

Thanks.

@krakjoe krakjoe closed this Jan 4, 2017
@php-pulls php-pulls merged commit 3372174 into php:master Jan 4, 2017
php-pulls pushed a commit that referenced this pull request Jan 4, 2017
* PHP-7.1:
  get_defined_functions additional parameter to exclude disabled functions
  news entry for PR #1312
@willianveiga willianveiga deleted the bug-31875-get_defined_functions-should-not-list-disabled-functions branch February 28, 2017 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.