Tuesday 4 May 2021

Php: get_declared_classes: Get all the classes that Php knows

Signature:

get_declared_classes ( ) : array

 

Description

Returns an array with the name of the defined classes.

 

Example

$declared_classes = get_declared_classes();

 

Find the below working example.

 

employee.php

<?php

class Employee{
    
}
?> 

student.php

<?php

class Student{
    
}
?> 


get_declared_classes_demo.php

#!/usr/bin/php

<?php

    include 'employee.php';
    include 'student.php';

    $declared_classes = get_declared_classes();

    print_r($declared_classes);
?> 


Output

$ ./get_declared_classes_demo.php 

Array
(
    [0] => stdClass
    [1] => Exception
    [2] => ErrorException
    [3] => Error
    [4] => CompileError
    [5] => ParseError
    [6] => TypeError
    [7] => ArgumentCountError
    [8] => ArithmeticError
    [9] => DivisionByZeroError
    [10] => Closure
    [11] => Generator
    [12] => ClosedGeneratorException
    [13] => DateTime
    [14] => DateTimeImmutable
    [15] => DateTimeZone
    [16] => DateInterval
    [17] => DatePeriod
    [18] => LibXMLError
    [19] => SQLite3
    [20] => SQLite3Stmt
    [21] => SQLite3Result
    [22] => CURLFile
    [23] => DOMException
    [24] => DOMStringList
    [25] => DOMNameList
    [26] => DOMImplementationList
    [27] => DOMImplementationSource
    [28] => DOMImplementation
    [29] => DOMNode
    [30] => DOMNameSpaceNode
    [31] => DOMDocumentFragment
    [32] => DOMDocument
    [33] => DOMNodeList
    [34] => DOMNamedNodeMap
    [35] => DOMCharacterData
    [36] => DOMAttr
    [37] => DOMElement
    [38] => DOMText
    [39] => DOMComment
    [40] => DOMTypeinfo
    [41] => DOMUserDataHandler
    [42] => DOMDomError
    [43] => DOMErrorHandler
    [44] => DOMLocator
    [45] => DOMConfiguration
    [46] => DOMCdataSection
    [47] => DOMDocumentType
    [48] => DOMNotation
    [49] => DOMEntity
    [50] => DOMEntityReference
    [51] => DOMProcessingInstruction
    [52] => DOMStringExtend
    [53] => DOMXPath
    [54] => HashContext
    [55] => finfo
    [56] => LogicException
    [57] => BadFunctionCallException
    [58] => BadMethodCallException
    [59] => DomainException
    [60] => InvalidArgumentException
    [61] => LengthException
    [62] => OutOfRangeException
    [63] => RuntimeException
    [64] => OutOfBoundsException
    [65] => OverflowException
    [66] => RangeException
    [67] => UnderflowException
    [68] => UnexpectedValueException
    [69] => RecursiveIteratorIterator
    [70] => IteratorIterator
    [71] => FilterIterator
    [72] => RecursiveFilterIterator
    [73] => CallbackFilterIterator
    [74] => RecursiveCallbackFilterIterator
    [75] => ParentIterator
    [76] => LimitIterator
    [77] => CachingIterator
    [78] => RecursiveCachingIterator
    [79] => NoRewindIterator
    [80] => AppendIterator
    [81] => InfiniteIterator
    [82] => RegexIterator
    [83] => RecursiveRegexIterator
    [84] => EmptyIterator
    [85] => RecursiveTreeIterator
    [86] => ArrayObject
    [87] => ArrayIterator
    [88] => RecursiveArrayIterator
    [89] => SplFileInfo
    [90] => DirectoryIterator
    [91] => FilesystemIterator
    [92] => RecursiveDirectoryIterator
    [93] => GlobIterator
    [94] => SplFileObject
    [95] => SplTempFileObject
    [96] => SplDoublyLinkedList
    [97] => SplQueue
    [98] => SplStack
    [99] => SplHeap
    [100] => SplMinHeap
    [101] => SplMaxHeap
    [102] => SplPriorityQueue
    [103] => SplFixedArray
    [104] => SplObjectStorage
    [105] => MultipleIterator
    [106] => JsonException
    [107] => SessionHandler
    [108] => __PHP_Incomplete_Class
    [109] => php_user_filter
    [110] => Directory
    [111] => AssertionError
    [112] => PDOException
    [113] => PDO
    [114] => PDOStatement
    [115] => PDORow
    [116] => PharException
    [117] => Phar
    [118] => PharData
    [119] => PharFileInfo
    [120] => ReflectionException
    [121] => Reflection
    [122] => ReflectionFunctionAbstract
    [123] => ReflectionFunction
    [124] => ReflectionGenerator
    [125] => ReflectionParameter
    [126] => ReflectionType
    [127] => ReflectionNamedType
    [128] => ReflectionMethod
    [129] => ReflectionClass
    [130] => ReflectionObject
    [131] => ReflectionProperty
    [132] => ReflectionClassConstant
    [133] => ReflectionExtension
    [134] => ReflectionZendExtension
    [135] => mysqli_sql_exception
    [136] => mysqli_driver
    [137] => mysqli
    [138] => mysqli_warning
    [139] => mysqli_result
    [140] => mysqli_stmt
    [141] => SimpleXMLElement
    [142] => SimpleXMLIterator
    [143] => SNMP
    [144] => SNMPException
    [145] => SoapClient
    [146] => SoapVar
    [147] => SoapServer
    [148] => SoapFault
    [149] => SoapParam
    [150] => SoapHeader
    [151] => tidy
    [152] => tidyNode
    [153] => XMLReader
    [154] => XMLWriter
    [155] => XSLTProcessor
    [156] => Employee
    [157] => Student
)


From the output, you can confirm that apart from built-in classes, Employee and Student classes are also known to Php.




 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment