防止PHP泄漏变量,包括或需要
我有不需要的参数泄漏到我的template.php
中。
function template($template, $args) {
$foo = $args['bar'];
extract($args);
include __DIR__ . '/' . $template . '.php';
}
在template.php
$ foo
应该不打印出某些内容,因为它不是从$ $ args
中提取的。$ bar
应该打印出一些东西,因为它是从$ args
中提取的。确实如此。$ Template
应该不打印出某物,因为它不是从$ args
中提取的。
<!DOCTYPE html>
<?= $foo; ?>
<?= $bar; ?>
<?= $template; ?>
</html>
在现实生活中,上述HTML是有效的。另外,我在模板
函数中还有更多参数。
我该如何解决论点泄漏?我可以通过在另一个功能中包装包装来更改范围,但是我仍然需要$ template
,然后将其传递给template.php
。
有什么想法吗?
I have unwanted arguments leaking into my template.php
.
function template($template, $args) {
$foo = $args['bar'];
extract($args);
include __DIR__ . '/' . $template . '.php';
}
In the template.php
$foo
should not print out something because it's not extracted from$args
.$bar
should print out something because it's extracted from$args
. It does.$template
should not print out something because it's not extracted from$args
.
<!DOCTYPE html>
<?= $foo; ?>
<?= $bar; ?>
<?= $template; ?>
</html>
In real life the HTML above is valid. Also, I have much more arguments in the template
function.
How can I get around argument leaking? I could change scope by wrapping include
in another function but then I still need $template
which will then be passed to the template.php
.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论