PHP,OOP,创建对象 [英] PHP, OOP, Creating an object

查看:59
本文介绍了PHP,OOP,创建对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习PHP,OOP,并且学到了很多东西,但是有些小东西在逗我,

I am Studying PHP, OOP and i have learned a lot, but there is small things who tease me,

我创建了一个用于说明对象创建的图像:链接

There is an image I created for illustration of object creation:Link

如果有人可以回答一些问题,请...

if someone could answer a few questions please...

  • 如果我对图像做错了什么,如果有人可以纠正我,我会很高兴.
  • 当我尝试 echo 一个对象时,我收到一条错误消息,指出该对象 (我知道对象是内存引用)(如果它不是内存位置名称的字符串(例如:'F70'),则不能转换为字符串)请问一个例子,说明内存位置的样子.
  • 关于包含引用的变量,我知道这是一个放置在所有其他全局变量中的常规变量,这意味着如果我创建新对象和新变量,则第一个对象(变量)将包含引用但这是一个常规的全局变量,其他变量也是如此:
  • I will be happy if some one can correct me if i did something wrong with the image.
  • When i try to echo an object i getting an error that say that the Object (i understand that the Object is the memory reference) cannot be converted to a string, if its not a string of the memory location name(example: 'F70') can i have an example please for how does memory location looks like.
  • And about the variable containing the reference, i understand that this is a regular variable placed with all the rest of the global variables, i mean that if i create new object and a new variable the first object(variable) contain the reference but it is a regular global variable, same is the other variable:

第一步:我定义对象变量...

First Step: i define the object variable...

第二步:创建对象,并将其内存位置放入我们想要的变量中...

Second Step: the Object created and it memory location getting inside the variable we wanted...

第三步:使用参考创建新的全局变量.

Third Step: New global variable created with our reference.

当我调用一个对象(变量)时意味着什么:

What mean that when i call a Object(variable):

第一步:我们要转到创建变量的内存位置...

First Step: We are going to the memory location where our variable created...

第二步:变量值(引用)将我们引向该对象所在的内存位置...

Second Step: The Variable value(reference) referring us to the memory location where the object is...

第三步:我们可以访问该对象的方法和属性.

Third Step: We have access to methods and properties of that object.

如果有人可以帮助我理解这一点,我会很高兴,谢谢大家,并度过愉快的一天.

I will be happy if some one can help me understand this things, thank you all and have a nice day.

推荐答案

  1. 要具有对象的字符串表示形式,必须实现功能 __toString()

关于内部机制-它比您想象的要复杂得多.由于PHP是一种动态语言,因此必须为每个类,每个类对象保留大量信息.不仅字符串变量需要内存,而且函数映射,内存管理结构,类型结构,默认值也是如此. 如果您想更深入,请阅读此书

Regarding internal mechanisms - its a lot lot more complicated than you think. As PHP is a dynamic language - it haas to keep a lot of information for every class, for every class object. Not just memory needed for string variable, but also function mapping, memory management structures, types structures, defaults.. If you want to get deeper, read this

这篇关于PHP,OOP,创建对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆