Note that this function also counts enums.
<?php
enum 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
Questa funzione non ha parametri.
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.
| Versione | Descrizione |
|---|---|
| 7.4.0 | In precedenza get_declared_classes() restituiva sempre le classi padre prima delle classi figlie. Questo non è più vero. Non è garantito alcun ordine particolare per il valore restituito da get_declared_classes(). |
Example #1 Esempio di get_declared_classes()
<?php
print_r(get_declared_classes());
?>Il precedente esempio visualizzerà qualcosa di simile a:
Array
(
[0] => stdClass
[1] => __PHP_Incomplete_Class
[2] => Directory
)
Note that this function also counts enums.
<?php
enum 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 classone
class classone { }
//define classtwo
class classtwo { }
//This will show X classes (built-ins, extensions etc) with
//classone and classtwo as the last two elements
print_r(get_declared_classes());
//define classthree
class classthree { }
//...and four
class classfour { }
//Shows the same result as before with class three and four appended
print_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
)