get_declared_classes()

get_declared_classes() — Returns an array with the name of the defined classes.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

Signature

get_declared_classes(): array

Parameters

This function takes no parameters.

Return value

Returns an array of the names of the declared classes in the current script. Note: Note that depending on what extensions you have compiled or loaded into PHP, additional classes could be present. This means that you will not be able to define your own classes using these names. There is a list of predefined classes in the Predefined Classes section of the appendices. Note that depending on what extensions you have compiled or loaded into PHP, additional classes could be present. This means that you will not be able to define your own classes using these names. There is a list of predefined classes in the Predefined Classes section of the appendices.

Example

A runnable snippet:

print_r(get_declared_classes());

Output:

Array ( [0] => stdClass [1] => __PHP_Incomplete_Class [2] => Directory )

Changelog

VersionChange
7.4.0Previously get_declared_classes() always returned parent classes before child classes. This is no longer the case. No particular order is guaranteed for the get_declared_classes() return value.

See also

class_exists(), get_declared_interfaces(), get_defined_functions()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page get_declared_classes() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.