Home > Backend Development > PHP Tutorial > Problems caused by unset destroying variables in PHP_PHP Tutorial

Problems caused by unset destroying variables in PHP_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:49:51
Original
858 people have browsed it

In PHP, if I want to destroy variables and store them, the standard way to write them is to use the unset() function directly. However, our test will find that unset only occurs when all variables pointing to the value (such as reference variables pointing to the value) are The address will not be released until it is destroyed. Let's look at a few examples below.

First let’s look at an example:

The code is as follows
 代码如下 复制代码

$a = "hello springload";
$b = $a;
unset($b);
echo $a; //hello springload
?>

Copy code

 代码如下 复制代码

$a = "hello springload";
$b = $a;
unset($a);
echo $b;//hello springload
?>

$a = "hello springload";
$b = $a;
​ unset($b);
echo $a; //hello springload
?>

 代码如下 复制代码

$a = "hello springload";
$b = $a;
unset($a);
unset($b);
echo $b;//输出空
?>

We know this very well, unset($b) only disconnects the variable name and value binding, but an interesting question arises:
The code is as follows
Copy code

$a = "hello springload";
$b = $a;
​ unset($a);
echo $b;//hello springload
?>

Why is $a destroyed, and why is the value of $b still there? Note: The unset() function will only release the address when all variables pointing to the value (such as reference variables pointing to the value) are destroyed, as follows:
The code is as follows Copy code
$a = "hello springload";
$b = $a;
​ unset($a);
​ unset($b);
echo $b;//output empty
?>
http://www.bkjia.com/PHPjc/632674.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632674.htmlTechArticleIn php, if I want to destroy variables and memory release the standard way to write them is to use the unset() function directly, but we The test will find that unset is only used when all variables pointing to the value (such as reference variables...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template