PHP | DOMImplementation hasFeature() Function

The DOMImplementation::hasFeature() function is an inbuilt function in PHP which is used to test if the DOM implementation implements a specific feature or not.

Syntax:

bool DOMImplementation::hasFeature( string $feature, string $version )

Parameters: This function accepts two parameters as mentioned above and described below:



  • $feature: It specifies the feature to test.
  • $version: It specifies the version number of the feature to test.

Return Value: This function returns TRUE on success or FALSE on failure.

Exceptions: This function throws E_STRICT exception on error.

Below examples illustrate the DOMImplementation::hasFeature() function in PHP:

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Write the feature name
$featureName1 = "Core";
  
// Check if it exists
$hasFeature1
    DOMImplementation::hasFeature($featureName1, '1.0');
if ($hasFeature1) {
    echo "Has feature $featureName1 module <br>";
}
  
// Write another feature name
$featureName2 = "XML";
  
// Check if it exists
$hasFeature2
    DOMImplementation::hasFeature($featureName2, '2.0');
if ($hasFeature2) {
    echo "Has feature $featureName2 module <br>";
}
?>  

chevron_right


Output:

Has feature Core module
Has feature XML module

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// Write the feature name
$featureName1 = "Events";
  
// Check if it doesn't exists
$hasFeature1
    DOMImplementation::hasFeature($featureName1, '1.0');
if (!$hasFeature1) {
    echo "Doesn't have feature $featureName1 module. <br>";
}
  
// Write another feature name
$featureName2 = "CSS";
  
// Check if it doesn't exists
$hasFeature2
    DOMImplementation::hasFeature($featureName2, '2.0');
if (!$hasFeature2) {
    echo "Doesn't have feature $featureName2 module. <br>";
}
?>  

chevron_right


Output:

Doesn't have feature Events module.
Doesn't have feature CSS module.

Reference: https://www.php.net/manual/en/domimplementation.hasfeature.php




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.