Home > Backend Development > PHP Tutorial > 辛星解析动态查看php中的变量、常量、函数、类、文件等信息

辛星解析动态查看php中的变量、常量、函数、类、文件等信息

WBOY
Release: 2016-06-23 13:51:56
Original
953 people have browsed it

     当我们php工作量变大之后,经常需要判断我们是否定义过某个变量,我们是否定义过某个常量,或者说我们是否定义过某个函数等等,我们重复定义常量会导致错误,我们重复定义变量会导致前面的值被覆盖,因此,还是很有必要去了解这些函数的。

    比如说我在我的starphp框架里写一个文件,代码如下:

<?phpecho "当前用户定义的常量";$user_constants = get_defined_constants(TRUE);print_r($user_constants['user']);echo "<br />";echo "当前引入的文件";$files = get_included_files();print_r($files);
Copy after login
然后去浏览器中执行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 )
Copy after login
当然读者并没有我的starphp的源代码,不过不用着急,我只是给大家演示这两个函数的作用,大家可以用手头的框架去演示,看看到底引入了哪些文件和定义了哪些常量,还是蛮不错的。


下面是这些函数的说明:

get_defined_vars:获取用户定义的变量get_defined_functions:获取所有已定义的函数get_loaded_extensions:获取所有可用的模块get_extension_funcs($module_name):获取指定模块的可用函数get_defined_constants():获取所有常量get_declared_classes():获取已定义的类get_included_files():获取导入的文件
Copy after login

感觉还是蛮有用的,因为今天我需要测试我是否定义了一个常量,也记载一下。。。。嘎嘎



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template