Closed (fixed)
Project:
Drupal core
Version:
11.2.x-dev
Component:
base system
Priority:
Normal
Category:
Plan
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
18 Dec 2010 at 17:15 UTC
Updated:
30 Jun 2025 at 02:48 UTC
Jump to comment: Most recent
Comments
Comment #1
avpadernoI am changing the issue title; probably Drupal core code needs to be changed more to allow to use methods as callbacks.
Comment #2
xanoI propose we fully deprecate the use of function_exists() in core and replace all occurences with is_callable(), except, of course, when checking for a specific predefined function and not for a callback.
API changes
No BC breaks.
Related issues
Comment #3
xanoSettings to needs review, so we can get reviews on this idea.
Comment #4
sidharthap@Xano there are some other modules also contains function_exists and not listed here. like system module. Is it to remove all existence of function_exists from Drupal core ?
Comment #5
xanoIf there are any other files or modules that still use function_exists() even though they shouldn't (note that some usages are valid), please create issues for them and add links to them in the issue summary.
Comment #6
xjmComment #7
dawehnerFor sure, it is not a bad idea to support any kind of callable.
In general there are usecases where function_exists() is more correct and provides a bit more local semantic:
Comment #8
dave reidComment #9
mile23I see 137 occurrences if
function_exists(). Some are within inline comments, though.Do we want to move on this? Split it up into separate issues?
Comment #16
jhedstromSince the last comment, there are now 145 occurrences of
function_exists(). I think this would still be worth tackling.Comment #17
avpadernoComment #25
smustgrave commentedComment #27
borisson_I agree, this is a good thing to do. Can we use phpstan to only allow the is_callable function?
Comment #28
quietone commentedThere is agreement here on making this change. And, in fact, there have been several issues implementing the change.
A policy decision should be accompanied with documentation. And there has been a suggestion to enforce this change. That implies this could be a coding standard. Although forbidding the use of a PHP function seems too string.
I have created a separate issue for doing the actual conversion, #3520416: [meta] Handle calls to functions that still require .module file autoloading.. Anyone wanting to discuss making this a coding standard should open an issue in the Coding Standards project.
With all that I think the work on this part is complete.
Comment #29
catchWith #3520416: [meta] Handle calls to functions that still require .module file autoloading. open I think we can just close this as fixed. I don't really see adding this as a coding standard, there are cases where you know you're looking for a specific function, like specific PHP functions that may or may not exist depending on installation.
Comment #31
quietone commentedChanging to latest version when this was closed.