Add separate checks for all polyfilled functions and constants #252
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As originally discussed in symfony/polyfill-mbstring#6 and later in #251 in some scenarios it may be better to check for each constant/function before defining it. Such scenarios are typically those where some project or a library defines its polyfills for some parts of extension functionality but not all of it.
Probably the most popular example is WordPress, defining some polyfills in
wp-includes/compat.php
but not including complete functionalities (i.e. it defines only a fewmb_
functions). Plugin developers then may need othermb_
functions and need to load those that WordPress didn't.There may be some performance concerns but it seems that checks such as
function_exists
are very fast - in fact, PHP tries to evaluate bothfunction_exists
anddefined
at compile time (see also StackOverflow). This means on installs that do have the polyfilled extensions installed, there should be zero overhead (the conditions will evaluate totrue
at compile time).Note that many of the currently existing polyfills already perform checks for each function separately (most of the PHP-version polyfills).
Closes #251.