get_declared_classes()函數是PHP中的內置函數,用於返回具有已定義類名稱的數組。用戶數組,其中包含當前腳本中所有system-defined(例如PDO,XML閱讀器等)的列表以及用戶定義的類。沒有為該函數提供參數。
<?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
)
排序列表:在如此龐大的清單中找到特定的課程可能很困難。但是,如果按字母順序對列表進行排序會更容易。可以通過函數排序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
)
參考: https://www.php.net/manual/en/function.get-declared-classes.php
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
相關用法
- d3.js d3.set.has()用法及代碼示例
- PHP Ds\Set contains()用法及代碼示例
- PHP Ds\Set last()用法及代碼示例
- PHP Ds\Set first()用法及代碼示例
- p5.js hex()用法及代碼示例
- p5.js arc()用法及代碼示例
- PHP dir()用法及代碼示例
- p5.js box()用法及代碼示例
- d3.js d3.mean()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- PHP exp()用法及代碼示例
- PHP Ds\Map first()用法及代碼示例
- PHP Ds\Map sum()用法及代碼示例
- PHP pi( )用法及代碼示例
- PHP Ds\Map get()用法及代碼示例
- d3.js d3.min()用法及代碼示例
注:本文由純淨天空篩選整理自sayesha大神的英文原創作品 PHP | get_declared_classes() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
