PHP/Reflection/get declared classes

Материал из Web эксперт
Перейти к: навигация, поиск

get_declared_classes() function returns an array of all defined classes.

   <source lang="html4strict">

Its syntax is: array get_declared_classes() <? class Vehicle { } class Car extends Vehicle { } $declared_classes = get_declared_classes(); print_r($declared_classes); ?> /* Array ( [0] => stdClass [1] => Exception [2] => ErrorException [3] => COMPersistHelper [4] => com_exception [5] => com_safearray_proxy [6] => variant [7] => com [8] => dotnet [9] => DateTime [10] => DateTimeZone [11] => ReflectionException [12] => Reflection [13] => ReflectionFunctionAbstract [14] => ReflectionFunction [15] => ReflectionParameter [16] => ReflectionMethod [17] => ReflectionClass [18] => ReflectionObject [19] => ReflectionProperty [20] => ReflectionExtension [21] => LibXMLError [22] => __PHP_Incomplete_Class [23] => php_user_filter [24] => Directory [25] => SimpleXMLElement [26] => DOMException [27] => DOMStringList [28] => DOMNameList [29] => DOMImplementationList [30] => DOMImplementationSource [31] => DOMImplementation [32] => DOMNode [33] => DOMNameSpaceNode [34] => DOMDocumentFragment [35] => DOMDocument [36] => DOMNodeList [37] => DOMNamedNodeMap [38] => DOMCharacterData [39] => DOMAttr [40] => DOMElement [41] => DOMText [42] => DOMComment [43] => DOMTypeinfo [44] => DOMUserDataHandler [45] => DOMDomError [46] => DOMErrorHandler [47] => DOMLocator [48] => DOMConfiguration [49] => DOMCdataSection [50] => DOMDocumentType [51] => DOMNotation [52] => DOMEntity [53] => DOMEntityReference [54] => DOMProcessingInstruction [55] => DOMStringExtend [56] => DOMXPath [57] => RecursiveIteratorIterator [58] => IteratorIterator [59] => FilterIterator [60] => RecursiveFilterIterator [61] => ParentIterator [62] => LimitIterator [63] => CachingIterator [64] => RecursiveCachingIterator [65] => NoRewindIterator [66] => AppendIterator [67] => InfiniteIterator [68] => RegexIterator [69] => RecursiveRegexIterator [70] => EmptyIterator [71] => ArrayObject [72] => ArrayIterator [73] => RecursiveArrayIterator [74] => SplFileInfo [75] => DirectoryIterator [76] => RecursiveDirectoryIterator [77] => SplFileObject [78] => SplTempFileObject [79] => SimpleXMLIterator [80] => LogicException [81] => BadFunctionCallException [82] => BadMethodCallException [83] => DomainException [84] => InvalidArgumentException [85] => LengthException [86] => OutOfRangeException [87] => RuntimeException [88] => OutOfBoundsException [89] => OverflowException [90] => RangeException [91] => UnderflowException [92] => UnexpectedValueException [93] => SplObjectStorage [94] => PDOException [95] => PDO [96] => PDOStatement [97] => PDORow [98] => ImagickException [99] => ImagickDrawException [100] => ImagickPixelIteratorException [101] => ImagickPixelException [102] => Imagick [103] => ImagickDraw [104] => ImagickPixelIterator [105] => ImagickPixel [106] => Collator [107] => NumberFormatter [108] => Normalizer [109] => Locale [110] => MessageFormatter [111] => IntlDateFormatter [112] => mysqli_sql_exception [113] => mysqli_driver [114] => mysqli [115] => mysqli_warning [116] => mysqli_result [117] => mysqli_stmt [118] => SoapClient [119] => SoapVar [120] => SoapServer [121] => SoapFault [122] => SoapParam [123] => SoapHeader [124] => SQLiteDatabase [125] => SQLiteResult [126] => SQLiteUnbuffered [127] => SQLiteException [128] => tidy [129] => tidyNode [130] => XMLReader [131] => XMLWriter [132] => XSLTProcessor [133] => ZipArchive [134] => Vehicle [135] => Car )

  • /
 </source>
   
  


If you are not sure which XML APIs might be available

   <source lang="html4strict">

<? $xmlfile = "myfile.xml"; $classes = get_declared_classes(); if( in_array("SimpleXMLElement", $classes) ) {

   $xmldoc = simplexml_load_file($xmlfile); 

} elseif( in_array("DOMDocument", $classes) ) {

   $xmldoc = new DOMDocument(); 
   $xmldoc->load($xmlfile); 

} else { } ?>

 </source>