Checks if the passed extension or function are available.
Description
Make the check for available PHP modules into a simple boolean operator for a cleaner test runner.
Parameters
$extension_name
stringoptional- The extension name to test.
Default:
null
$function_name
stringoptional- The function name to test.
Default:
null
$constant_name
stringoptional- The constant name to test for.
Default:
null
$class_name
stringoptional- The class name to test for.
Default:
null
Source
private function test_php_extension_availability( $extension_name = null, $function_name = null, $constant_name = null, $class_name = null ) {
// If no extension or function is passed, claim to fail testing, as we have nothing to test against.
if ( ! $extension_name && ! $function_name && ! $constant_name && ! $class_name ) {
return false;
}
if ( $extension_name && ! extension_loaded( $extension_name ) ) {
return false;
}
if ( $function_name && ! function_exists( $function_name ) ) {
return false;
}
if ( $constant_name && ! defined( $constant_name ) ) {
return false;
}
if ( $class_name && ! class_exists( $class_name ) ) {
return false;
}
return true;
}
User Contributed Notes
You must log in before being able to contribute a note or feedback.