为什么要UNSET?

dinoalex dinoalex 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
[code=PHP]
final class MyClass {
public $get = array();
public $post = array();
public $cookie = array();
public $files = array();
public $server = array();

public function __construct() {
$_GET = $this->clean($_GET);
$_POST = $this->clean($_POST);
$_COOKIE = $this->clean($_COOKIE);
$_FILES = $this->clean($_FILES);
$_SERVER = $this->clean($_SERVER);

$this->get = $_GET;
$this->post = $_POST;
$this->cookie = $_COOKIE;
$this->files = $_FILES;
$this->server = $_SERVER;
}

public function clean($data) {
if (is_array($data)) {
foreach ($data as $key => $value) {
unset($data[$key]);

$data[$this->clean($key)] = $this->clean($value);
}
} else {
$data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8');
}

return $data;
}
}
[/Code]

用echo回显了相关变量, new 一个 MyClass 后, 又回显一次, 没什么不同啊..

就是奇怪,这些网上的代码,经常性了unset一下一些全局变量.
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
dinoalex
基础编程 21,889 成员 140,329 内容