什么是OOP中的静态和动态变量/方法? [英] What are static and dynamic variables / methods in OOP?

查看:85
本文介绍了什么是OOP中的静态和动态变量/方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图更好地理解OOP中的基本概念. 面向对象编程中的静态和动态变量和方法是什么? 例如,使用$ this与双冒号(::)之间的区别是什么?

I am trying to better understand basic concepts in OOP. What are static and dynamic variables and methods in object-oriented programming? What is, for instance, the difference between using $this vs. double colon (::)?

  • 优点:?.
  • 缺点:? ..."this"不是自记录文档,如$this->method_from_an_extended_class().
  • 优势:?
  • 缺点:?

推荐答案

静态"和动态"不是正确的描述.

"Static" and "dynamic" aren't the right descriptions for that.

->表示实例函数实例数据,表示该函数或数据具有隐式的$this引用.换句话说,您是指特定对象中的函数或变量.

-> indicates a instance functions or instance data, meaning that the function or data has an implicit $this reference. To put it another way you're referring to the function or variable within a particular object.

::表示类函数类变量.这与全局函数或变量非常相似,因为没有隐式$this引用.该类的所有实例都共享该函数或变量.

:: indicates a class function or class variable. This is very similar to a global function or variable in that there is no implicit $this reference. All instance of that class share that function or variable.

动态"是对 PHP重载的更准确的描述,在这里您可以动态地例如,使用魔术方法__get()__set()(当您尝试访问找不到的属性时会调用它们;可以重载这些方法以实质上假装所请求的成员存在)来创建变量.

"Dynamic" would be a more accurate description for, say, PHP overloading where you can "dynamically" create variables, for example, using the magic methods __get() and __set() (which are called when you try to access a property that can't be found; you can overload these methods to essentially pretend the requested member exists).

这篇关于什么是OOP中的静态和动态变量/方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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