变量全局变量?
我正在尝试自动清理全局变量数组上的输入,如下所示:
$sanitize = array('_POST', '_GET', '_REQUEST', '_COOKIE', '_SESSION');
foreach($sanitize as $type){
$property = trim(strtolower($type), '_');
$this->$property = $this->cleanse($$type);
}
但我得到: Notice: Undefined variable: _REQUEST
(对于我正在尝试的所有全局变量,依此类推)
是做我想要完成的事情实际上可能吗?
谢谢。
I'm trying to automatically sanitize input on an array of global variables like so:
$sanitize = array('_POST', '_GET', '_REQUEST', '_COOKIE', '_SESSION');
foreach($sanitize as $type){
$property = trim(strtolower($type), '_');
$this->$property = $this->cleanse($type);
}
But I get: Notice: Undefined variable: _REQUEST
(and so on for all of the global variables I'm trying)
Is doing what I'm trying to accomplish actually possible?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在全球范围内这样做通常会遭到反对。
我建议使用一些 PHP 内置的 过滤器 来实现您的目的希望在地方一级。这只是根据您需要过滤您需要的内容。
Doing this on a global scale is typically frowned upon.
I'd recommend using some of PHP's built in Filters to achieve what you want at a local level. That is just filter what you need as you need it.