Detailed explanation of how PHP outputs all variables/constants/modules/functions/class codes

伊谢尔伦
Release: 2023-03-12 08:02:02
Original
4871 people have browsed it

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 &#39;<pre class="brush:php;toolbar:false">&#39;;
$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()));
?>
Copy after login

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 &#39;<pre class="brush:php;toolbar:false">&#39;;
function foo()
{
    echo "This is my function foo";
}
$arr = get_defined_functions();
print_r($arr);
?>
Copy after login


3. get_loaded_extensions (PHP 4, PHP 5) — Get all available modules

<?php
echo &#39;<pre class="brush:php;toolbar:false">&#39;;
print_r(get_loaded_extensions());
?>
Copy after login


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 &#39;<pre class="brush:php;toolbar:false">&#39;;
print_r(get_extension_funcs("gd"));
print_r(get_extension_funcs("xml"));
?>
Copy after login


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 &#39;<pre class="brush:php;toolbar:false">&#39;;
define("MY_CONSTANT", 1);
print_r(get_defined_constants(true));
?>
Copy after login


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 &#39;<pre class="brush:php;toolbar:false">&#39;;
//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());
?>
Copy after login


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!

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