Home  >  Article  >  php教程  >  php对象在内存中的存在形式分析

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

WBOY
WBOYOriginal
2016-06-06 20:11:081001browse

这篇文章主要介绍了php对象在内存中的存在形式,实例分析了对象在内存中的存储及运算原理,具有一定参考借鉴价值,需要的朋友可以参考下

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

name = "小明"; $p1->age=80; $p2=$p1; $p2->age=85; echo $p2->name; echo $p1->age; ?>

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

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

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

Statement:
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