Home > php教程 > php手册 > body text

php对象在内存中的存在形式分析,php对象内存形式

WBOY
Release: 2016-06-13 09:15:38
Original
1248 people have browsed it

php对象在内存中的存在形式分析,php对象内存形式

本文实例分析了php对象在内存中的存在形式。分享给大家供大家参考。具体分析如下:

<&#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对应内存地址,假设是0x123,($p1和地址存放在栈区,相当于我们查字典时的索引);
(2)通过内存地址的索引,找到堆区。堆区里面存放着”小王“,”80“等数据
(3)$p2 = $p1,实际上是将$p1的内存地址0x123传给$p2,堆区里的属性$name,$age不变,也就是不会再重新复制一份。所以,在改变$p2->age=85时,$p1->age的值也改变了。

希望本文所述对大家的php程序设计有所帮助。

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 Recommendations
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!