PHP: Get PHP#39;s variables, functions, constants from a php file(PHP:从一个php文件中获取PHP的变量、函数、常量)
问题描述
有没有办法从 php 文件中获取用户定义的 php 函数、变量、常量?以下功能不是最好的方法,因为它们都被贴花functions/vars/constants(带有数百个 php 的内置常量和内部 php 函数):
Is there a way to get user-defined php functions, variables, constants from a php file? Following functions are not the best way to do so because they get all decalred functions/vars/constants (with hundreds of php's built-in constants and internal php functions):
get_defined_vars
get_defined_functions
get_defined_constants
假设我有这个文件myfile.php:
<?php
$title = "U2FtcGxlIEFwcGxpY2F0aW9u";
$copyright = 'Copyright © 2009';
$my_array = array('sarfraz', 'ahmed', 'chandio');
define ('_CASTE', 'chandio');
define ('_COUNTRY', 'Pakistan');
function add($val1, $val2)
{
return ($val1 + $val2);
}
function subtract($val1, $val2)
{
return ($val1 - $val2);
}
?>
现在我如何从该文件中获取所有变量/函数/常量并可能存储在一个数组中?
Now how can i get all variables/functions/constants from that file and probably store in an array?
谢谢
推荐答案
你可能想试试 PHP Tokenizer.
You probably want to try the PHP Tokenizer.
http://www.php.net/manual/en/ref.tokenizer.php
来自外部脚本:
<?php
var_dump(token_get_all(file_get_contents('myscript.php')));
?>
这篇关于PHP:从一个php文件中获取PHP的变量、函数、常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP:从一个php文件中获取PHP的变量、函数、常量


- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- Laravel 仓库 2022-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01