Example of PHP outputting all variables, constants, modules, functions, and classes of the current process
1. get_defined_vars (PHP 4 >= 4.0.4, PHP 5) — Get by Array of all defined variables
array get_defined_vars (void)
This function returns a multidimensional array containing a list of all defined variables, including environment variables , server variables and user-defined variables.
<?php echo '<pre class="brush:php;toolbar:false">'; $b = array(1,1,2,3,5,8); $arr = get_defined_vars(); // 打印 $b print_r($arr["b"]); // 打印所有服务器变量 print_r($arr["_SERVER"]); // 打印变量数组的所有可用键值 print_r(array_keys(get_defined_vars())); ?>
2. get_defined_functions (PHP 4 >= 4.0.4, PHP 5) — Get all defined functions
array get_defined_functions (void) //void means empty and does not require any parameters
<?php echo '<pre class="brush:php;toolbar:false">'; function foo() { echo "This is my function foo"; } $arr = get_defined_functions(); print_r($arr); ?>
3. get_loaded_extensions (PHP 4, PHP 5) — Get all available modules
<?php echo '<pre class="brush:php;toolbar:false">'; print_r(get_loaded_extensions()); ?>
4. get_extension_funcs (PHP 4, PHP 5) — Get the available functions of the specified module
array get_extension_funcs ( string $module_name ) This function returns all available functions of the specified module. The passed-in parameter (module name) must be lowercase
<?php echo '<pre class="brush:php;toolbar:false">'; print_r(get_extension_funcs("gd")); print_r(get_extension_funcs("xml")); ?>
5. get_defined_constants (PHP 4 >= 4.1.0, PHP 5) — Get the names of all constants and their values in an associative array
array get_defined_constants ([ bool $categorize = false ] )
<?php echo '<pre class="brush:php;toolbar:false">'; define("MY_CONSTANT", 1); print_r(get_defined_constants(true)); ?>
6. get_declared_classes (PHP 4, PHP 5) — Get an array consisting of the names of defined classes
array get_declared_classes (void)
<?php echo '<pre class="brush:php;toolbar:false">'; //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()); ?>
The above is the detailed content of Detailed explanation of how PHP outputs all variables/constants/modules/functions/class codes. For more information, please follow other related articles on the PHP Chinese website!