PHP-面向对象(类和对象在内存中的分布)

1.8 类和对象在内存中的分布

  1. 对象的本质是一个复杂的变量
  2. 类的本质是一个自定义的复杂数据类型
  3. 栈区:运行速度快,体积小,保存基本类型
  4. 堆区:运行速度稍慢,体积大,保存复杂类型
  5. 实例化的过程就是分配内存空间的过程
  6. 对象保存在堆区,将堆区的地址保存到栈区。

分析如下代码的结构

<?php
class Student {
	public $name;
	public $sex;
	public function show() {
	}
}

$stu1=new Student;
$stu2=new Student;

$stu1->show();

示意图

在这里插入图片描述

发布了1891 篇原创文章 · 获赞 2010 · 访问量 18万+

猜你喜欢

转载自blog.csdn.net/weixin_42528266/article/details/105138693