DOMImplementation::hasFeature

(PHP 5, PHP 7, PHP 8)

DOMImplementation::hasFeature Test if the DOM implementation implements a specific feature

說(shuō)明

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

Test if the DOM implementation implements a specific feature.

You can find a list of all features in the ? Conformance section of the DOM specification.

參數(shù)

feature

The feature to test.

version

The version number of the feature to test. In level 2, this can be either 2.0 or 1.0.

返回值

成功時(shí)返回 true, 或者在失敗時(shí)返回 false

錯(cuò)誤/異常

在 PHP 8.0.0 之前可以靜態(tài)調(diào)用此方法,但會(huì)發(fā)出 E_DEPRECATED 錯(cuò)誤。自 PHP 8.0.0 起,靜態(tài)調(diào)用此方法會(huì)拋出 Error 異常

范例

示例 #1 Testing your DOM Implementation

<?php

$features 
= array(
  
'Core'           => 'Core module',
  
'XML'            => 'XML module',
  
'HTML'           => 'HTML module',
  
'Views'          => 'Views module',
  
'Stylesheets'    => 'Style Sheets module',
  
'CSS'            => 'CSS module',
  
'CSS2'           => 'CSS2 module',
  
'Events'         => 'Events module',
  
'UIEvents'       => 'User interface Events module',
  
'MouseEvents'    => 'Mouse Events module',
  
'MutationEvents' => 'Mutation Events module',
  
'HTMLEvents'     => 'HTML Events module',
  
'Range'          => 'Range module',
  
'Traversal'      => 'Traversal module'
);
               
foreach (
$features as $key => $name) {
  if (
DOMImplementation::hasFeature($key'2.0')) {
    echo 
"Has feature $name\n";
  } else {
    echo 
"Missing feature $name\n";
  }
}

?>

參見(jiàn)