In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.