为什么要UNSET?
[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一下一些全局变量.
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一下一些全局变量.
...全文
相关推荐
Git别名的使用
为什么要使用Git别名? 使用Git别名主要有以下几个好处: - **提高效率**:通过创建简短的别名,我们可以减少输入命令的时间,特别是在频繁使用某些命令时。
PHP unset函数原理及使用方法解析
例如:```php// 销毁单个变量unset($foo);// 销毁数组的一个元素unset($bar['quux']);// 销毁多个变量unset($foo1, $foo2, $foo3);```
unset命令 删除指定的shell变量或函数
unset命令是Linux和Unix shell环境中一个重要的命令,用于删除已定义的shell变量和shell函数。这个命令在编程和系统管理中常被用来清理环境,确保不会意外保留无用的配置或临时数据。
PHP中使用unset销毁变量并内存释放问题
但是,垃圾回收机制并非在每次unset操作后立即执行,而是定期执行的。这意味着在某些情况下,即使使用了unset(),由于垃圾回收尚未运行,内存可能看起来没有得到释放。
PHP中isset()和unset()函数的用法小结
**unset()函数**unset()函数用于销毁一个变量,使其从当前作用域中删除。


基础编程
