PHP:从php文件中获取PHP的变量,函数和常量 [英] PHP: Get PHP's variables, functions, constants from a php file
本文介绍了PHP:从php文件中获取PHP的变量,函数和常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法从php文件中获取用户定义的php函数,变量,常量?
以下函数不是最好的方法,因为它们得到所有decalred
函数/ vars /常量(有数百个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 = 'Sample Application';
$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的变量,函数和常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文