In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Php destroy variables in two ways is what, for this problem, this article describes the corresponding analysis and solution in detail, hoping to help more want to solve this problem of small partners to find a simpler and easier way.
There are two ways to destroy variables in php: 1. use the unset() function, syntax "unset($varname)";2. assign the specified variable "NULL", syntax "$varname=null;".
Operating environment of this tutorial: Windows 7 system, PHP 7.1 version, DELL G3 computer
PHP variable or object destruction can be divided into explicit and implicit destruction:
Explicit destruction, when the object is not referenced will be destroyed, so we can unset or assign NULL to it;
2, implicit destruction, PHP is a scripting language, in the code execution of the last line, all the application of memory to be released.
Therefore, there are two ways to destroy variables:
unset()
$varname=null
For example:
class Human { public $name = ''; public $gender = null; public function __destruct() { echo 'dead! '; } } $a = new Human(); $b = $c = $d = $a;unset($a);$d=null;echo '';var_dump($a);echo '';var_dump($b);echo '';var_dump($c);echo '';var_dump($d);
The results were as follows:
Notice: Undefined variable: a in/Library/WebServer/Documents/test.php on line 42NULLobject(Human)#1 (2) { ["name"]=> string(6) "Zhang San" ["gender"]=> NULL }object(Human)#1 (2) { ["name"]=> string(6) "Zhang San" ["gender"]=> NULL }NULL Dead!
First of all, we need to know that in PHP, variable names are stored in the memory stack. It is an address that points to specific memory in the heap. We can find memory in the heap by variable names; therefore, we can conclude:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.