Analysis of the existence form of php objects in memory, memory form of php objects_PHP tutorial

WBOY
Release: 2016-07-13 10:07:54
Original
1075 people have browsed it

Analysis of the existence form of php objects in memory, memory form of php objects

The example of this article analyzes the existence form of PHP objects in memory. Share it with everyone for your reference. The specific analysis is as follows:

<&#63;php
class Person{
 public $name;
 public $age;
}
$p1 = new Person();
$p1->name = "小明";
$p1->age=80;
$p2=$p1;
$p2->age=85;
echo $p2->name;
echo $p1->age;
&#63;>
Copy after login

(1) $p1 corresponds to the memory address, assuming it is 0x123, ($p1 and the address are stored in the stack area, which is equivalent to the index when we look up the dictionary);
(2) Find the heap area through the index of the memory address. The heap area stores data such as "Xiao Wang" and "80"
(3) $p2 = $p1, in fact, the memory address 0x123 of $p1 is passed to $p2. The attributes $name and $age in the heap area remain unchanged, that is, they will not be copied again. Therefore, when changing $p2->age=85, the value of $p1->age also changes.

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/953155.htmlTechArticleAnalysis of the existence form of php objects in memory, memory form of php objects. This article analyzes the existence form of php objects in memory through examples. form of existence. Share it with everyone for your reference. The specific analysis is as follows:...
Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!