The get_declared_classes() function is an inbuilt function in PHP which is used to return an array with the name of the defined classes. The user array containing the list of all the system-defined(for example, PDO, XML reader, etc) and user-defined classes in the present script. No parameters are given to this function.
<?php class gfg { function add () { $a = 9 + 2 ; } } class gfg1 { function tr() { echo (4); } } print_r(get_declared_classes()); ?> |
Array ( [0] => stdClass [1] => Exception [2] => ErrorException [3] => Error [4] => ParseError . . . [155] => Ds\PriorityQueue [156] => Ds\Pair [157] => gfg [158] => gfg1 )
Sorting the list: Finding a particular class in such a big list can be difficult. But it can be easier if the list is sorted alphabetically. It can be sorted through the function sort()
.
<?php $sorted = get_declared_classes(); sort( $sorted ); print_r( $sorted ); ?> |
Array ( [0] => AppendIterator [1] => ArithmeticError [2] => ArrayIterator [3] => ArrayObject [4] => AssertionError . . . [152] => XMLWriter [153] => __PHP_Incomplete_Class [154] => finfo [155] => php_user_filter [156] => stdClass )
Reference: https://www.php.net/manual/en/function.get-declared-classes.php