PHP輸出當前進程所有變量 / 常量 / 模塊 / 函數 / 類

1. get_defined_vars  (PHP 4 >= 4.0.4, PHP 5) — 獲取由所有已定義變量所組成的數組

 

array get_defined_vars ( void )

 

此函數返回一個包含所有已定義變量列表的多維數組,這些變量包括環境變量、服務器變量和用戶定義的變量。

 

Php代碼  收藏代碼
  1. <?php  
  2. echo '<pre>';  
  3.   
  4. $b = array(1,1,2,3,5,8);  
  5.   
  6. $arr = get_defined_vars();  
  7.   
  8. // 打印 $b  
  9. print_r($arr["b"]);  
  10.   
  11. // 打印所有服務器變量  
  12. print_r($arr["_SERVER"]);  
  13.   
  14. // 打印變量數組的所有可用鍵值  
  15. print_r(array_keys(get_defined_vars()));  
  16. ?>  
 

2. get_defined_functions (PHP 4 >= 4.0.4, PHP 5) — 獲取所有已經定義的函數

 

array get_defined_functions ( void ) //void 表示爲空,不需要任何參數

 

Php代碼  收藏代碼
  1. <?php  
  2. echo '<pre>';  
  3.   
  4. function foo()  
  5. {  
  6.     echo "This is my function foo";  
  7. }  
  8. $arr = get_defined_functions();  
  9. print_r($arr);  
  10.   
  11. ?>  

 

3. get_loaded_extensions (PHP 4, PHP 5) — 獲取所有可用的模塊

 

Php代碼  收藏代碼
  1. <?php  
  2. echo '<pre>';  
  3.   
  4. print_r(get_loaded_extensions());  
  5. ?>  
 

4. get_extension_funcs (PHP 4, PHP 5) — 獲取指定模塊的可用函數

 

array get_extension_funcs ( string $module_name ) 該函數返回指定模塊所有可用的函數。傳入的參數(模塊名稱)必須是小寫

 

Php代碼  收藏代碼
  1. <?php  
  2. echo '<pre>';  
  3.   
  4. print_r(get_extension_funcs("gd"));  
  5. print_r(get_extension_funcs("xml"));  
  6. ?>  
 

5. get_defined_constants (PHP 4 >= 4.1.0, PHP 5) —  獲取關聯數組的名字所有的常量和他們的價值

 

array get_defined_constants ([ bool $categorize = false ] )

 

Php代碼  收藏代碼
  1. <?php  
  2. echo '<pre>';  
  3.   
  4. define("MY_CONSTANT", 1);  
  5. print_r(get_defined_constants(true));  
  6. ?>  
 

6. get_declared_classes (PHP 4, PHP 5) —  獲取由已定義類的名字所組成的數組

 

array get_declared_classes ( void )

 

Php代碼  收藏代碼
  1. <?php  
  2. echo '<pre>';  
  3.   
  4. //define classone  
  5. class classone { }  
  6.   
  7. //define classtwo  
  8. class classtwo { }  
  9.   
  10. //This will show X classes (built-ins, extensions etc) with  
  11. //classone and classtwo as the last two elements  
  12.   
  13. print_r(get_declared_classes());  
  14.   
  15. //define classthree  
  16. class classthree { }  
  17.   
  18. //...and four  
  19. class classfour { }  
  20.   
  21. //Shows the same result as before with class three and four appended  
  22. print_r(get_declared_classes());  
  23. ?>  
 

7. get_included_files()(或者get_require_files) (PHP 4, PHP 5) —  獲取由已定義類的名字所組成的數組

   

<?php
// This file is abc.php

include 'test1.php';
include_once 'test2.php';
require 'test3.php';
require_once 'test4.php';

$included_files = get_included_files();

foreach ($included_files as $filename) {
    echo "$filename\n";
}

?>

發佈了15 篇原創文章 · 獲贊 4 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章