辛星解析動態查看php中的變數、常量、函數、類、檔案等資訊

來源:互聯網
上載者:User
當我們php工作量變大之後,經常需要判斷我們是否定義過某個變數,我們是否定義過某個常量,或者說我們是否定義過某個函數等等,我們重複定義常量會導致錯誤,我們重複定義變數會導致前面的值被覆蓋,因此,還是很有必要去瞭解這些函數的。

比如說我在我的starphp架構裡寫一個檔案,代碼如下:

";echo "當前引入的檔案";$files = get_included_files();print_r($files);
然後去瀏覽器中執行url:http://localhost/starshop/index.php

那麼輸出的結果為:

目前使用者定義的常量Array ( [ROOT] => D:\MyApp\wamp\www\starshop [D] => \ [STAR] => D:\MyApp\wamp\www\starshop\star [CORE] => D:\MyApp\wamp\www\starshop\star\core [HOST] => localhost [APP] => D:\MyApp\wamp\www\starshop\app [LOG] => D:\MyApp\wamp\www\starshop\app\data\log [MODULE] => D:\MyApp\wamp\www\starshop\app\index [VIEW] => D:\MyApp\wamp\www\starshop\app\index\view ) 當前引入的檔案Array ( [0] => D:\MyApp\wamp\www\starshop\index.php [1] => D:\MyApp\wamp\www\starshop\star\star.php [2] => D:\MyApp\wamp\www\starshop\star\core\config.php [3] => D:\MyApp\wamp\www\starshop\star\core\fun.php [4] => D:\MyApp\wamp\www\starshop\star\core\core.php [5] => D:\MyApp\wamp\www\starshop\star\core\control.php [6] => D:\MyApp\wamp\www\starshop\app\index\control\index.c.php [7] => D:\MyApp\wamp\www\starshop\app\index\view\index.php )
當然讀者並沒有我的starphp的原始碼,不過不用著急,我只是給大家示範這兩個函數的作用,大家可以用手頭的架構去示範,看看到底引入了哪些檔案和定義了哪些常量,還是蠻不錯的。


下面是這些函數的說明:

get_defined_vars:擷取使用者定義的變數get_defined_functions:擷取所有已定義的函數get_loaded_extensions:擷取所有可用的模組get_extension_funcs($module_name):擷取指定模組的可用函數get_defined_constants():擷取所有常量get_declared_classes():擷取已定義的類get_included_files():擷取匯入的檔案

感覺還是蠻有用的,因為今天我需要測試我是否定義了一個常量,也記載一下。。。。嘎嘎
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.