简体   繁体   English

PHP - 获取包含文件中定义的变量

[英]PHP - get variables defined on included file

On PHP I have one very specific situation.PHP我有一种非常具体的情况。

Imagine I have the following code:想象一下,我有以下代码:

index.php索引.php

<?
$a = "1";
$b = "2";
include("other.php");
$c = "3";
$d = "4";
?>

other.php其他.php

<?
$x = "11";
$y = "12";
?>

Then imagine that I don't have the source code of the file: other.php (this seems weird but assume that).然后想象我没有文件的源代码: other.php (这看起来很奇怪,但假设)。 Then, I would like, from the source code of: index.php , get some information about the variables defined on other.php , or maybe the source code.然后,我想从index.php的源代码中获取有关other.php定义的变量的一些信息,或者可能是源代码。 My requirements doesn't allow me to open the content of the file: "other.php".我的要求不允许我打开文件的内容:“other.php”。

Could I maybe store the state of the system before and after the call to: other.php and then do a state substraction to see what have changed?我可以在调用之前和之后存储系统的状态: other.php然后进行状态减法以查看发生了什么变化?

Unfortunatelly I cannot manipulate the file: other.php .不幸的是,我无法操作文件: other.php

[UPDATE] [更新]

My problem, is because I have a website with an encoded file (on the code above it is: other.php ).我的问题是因为我有一个带有编码文件的网站(上面的代码是: other.php )。 That encoding is done with Zend Guard Loader .该编码是使用Zend Guard Loader What Zend does here is take the encoded code at the bottom of the following fragment of code and convert it to PHP source code at some point and then execute it as source code. Zend 在这里所做的是将以下代码片段底部的编码代码在某个时刻转换为 PHP 源代码,然后将其作为源代码执行。 I don't have the original source code, just the encoded code.我没有原始源代码,只有编码后的代码。

Then I would like to get the source code of that file somehow.然后我想以某种方式获取该文件的源代码。

The problem here is that on this code could be defined functions, variables with static assignments and variables with dynamic assignments (getting it's values from function results).这里的问题是在这段代码中可以定义函数、静态赋值的变量和动态赋值的变量(从函数结果中获取它的值)。

The ideal for me would be get the source code some how.对我来说最理想的方式是获取源代码。

The website is working correctly, so, the decoding is done correctly.该网站工作正常,因此,解码正确完成。

<?php @Zend;
4123;
/* This is not a text file */
print <<<EOM
<html><body><a href="http://www.zend.com/products/zend_guard"><img border="0" src="http://www.zend.com/images/store/safeguard_optimizer_img.gif" align="right"></a><center><h1>Zend Optimizer not installed</h1></center><p>This file was encoded by the <a href="http://www.zend.com/products/zend_guard">Zend Guard</a>. In order to run it, please install the <a href="http://www.zend.com/products/zend_optimizer">Zend Optimizer</a> (available without charge), version 3.0.0 or later. </p><h2>Seeing this message instead of the website you expected?</h2>This means that this webserver is not configured correctly. In order to view this website properly, please contact the website's system administrator/webmaster with the following message:<br><br><tt>The component "Zend Optimizer" is not installed on the Web Server and therefore cannot service encoded files. Please download and install the Zend Optimizer (available without charge) on the Web Server.</tt><br><br><b>Note</b>: Zend Technologies cannot resolve issues related to this message appearing on websites not belonging to <a href="http://www.zend.com">Zend Technologies</a>. <h2>What is the Zend Optimizer?</h2><p>The Zend Optimizer is one of the most popular PHP plugins for performance-improvement, and has been available without charge, since the early days of PHP 4. It improves performance by scanning PHP's intermediate code and passing it through multiple Optimization Passes to replace inefficient code patterns with more efficient code blocks. The replaced code blocks perform exactly the same operations as the original code, only faster. </p><p>In addition to improving performance, the Zend Optimizer also enables PHP to transparently load files encoded by the Zend Guard. </p><p>The Zend Optimizer is a free product available for download from <a href="http://www.zend.com">Zend Technologies</a>. Zend Technologies also developed the PHP scripting engine, known as the <a href="http://www.zend.com/products/zend_engine">Zend Engine</a>.</p></body></html>
EOM;
exit();
__halt_compiler();

2003120702‚–ÛUÕ_Eq7X-‡äÂK.½Iëoôïîuolÿ@f*vÈ9õ]¾2003120702‚–ÛUÕ_Eq7X-‡äÂK.½Iëoôïîuolÿ@f*vÈ9õ]¾2003120702‚–ÛUÕ_Eq7X-‡äÂK.½Iëoôïîuolÿ@f*vÈ9õ]¾2003120702‚–ÛUÕ_Eq7X-‡äÂK.½Iëoôïîuolÿ@f*vÈ9õ]¾
... the code continues ...

This might help (note that I just added the contents of your include directly, so the code is runnable with some result... there would still just be your include in that case):这可能会有所帮助(请注意,我只是直接添加了包含的内容,因此代码可以运行并产生一些结果......在这种情况下仍然只有您的包含):

<?php

$a = 1;
$b = 2;

$preVars = null; // Define it so it doesn't show up later
$preVars = array_keys(get_defined_vars());

// Normally included, just here for tests sake
$x = 10;
$y = 11;
// End of your include

$postVars = array_keys(get_defined_vars());

$c = 3;
$d = 4;

$diff = array_diff($postVars, $preVars);

echo "New Variables:\n";
foreach($diff as $d)
echo "- \$".$d."\n";

Output:输出:

New Variables:
- $x
- $y

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM