Note that this function also counts enums.<?phpenum Bla{ case Foo;}var_dump(get_declared_classes());?>Result:array(116) { ... [115]=> string(3) "Bla"}
(PHP 4, PHP 5, PHP 7, PHP 8)
get_declared_classes — Restituisce un array con i nomi delle classi definite
Restituisce un array con i nomi delle classi dichiarate nel codice corrente.
Nota:
Notare che in base alle estensioni compilate o caricate in PHP, potrebbero essere presenti classi aggiuntive. Questo significa che non si sarà in grado di definire le proprie classi usando questi nomi. C'è una lista delle classi predefinite nella sezione Classi Predefinite dell'appendice.
Example #1 Esempio di get_declared_classes()
<?php
print_r(get_declared_classes());
?>
Il precedente esempio visualizzerà qualcosa simile a:
Array ( [0] => stdClass [1] => __PHP_Incomplete_Class [2] => Directory )
Note that this function also counts enums.<?phpenum Bla{ case Foo;}var_dump(get_declared_classes());?>Result:array(116) { ... [115]=> string(3) "Bla"}
The array returned by this function will be in the order the classes were defined / included / required and this order does not appear to change.For example:<?PHP//define classoneclass classone { }//define classtwoclass classtwo { }//This will show X classes (built-ins, extensions etc) with//classone and classtwo as the last two elementsprint_r(get_declared_classes());//define classthreeclass classthree { }//...and fourclass classfour { }//Shows the same result as before with class three and four appendedprint_r(get_declared_classes());?>Output:Array( [0] => stdClass [1] .... other defined classes.... [10] => classone [11] => classtwo )and...Array( [0] => stdClass [1] .... other defined classes.... [10] => classone [11] => classtwo [12] => classthree [13] => classfour)