开发者

difference between property accessor

开发者 https://www.devze.com 2023-03-03 04:22 出处:网络
What is the difference between accessing a property from the class through $this or through new operator or through scope resolution operator in PHP?

What is the difference between accessing a property from the class through $this or through new operator or through scope resolution operator in PHP?

$this-> vs ->开发者_运维技巧 vs :: in PHP


$this-> can be used from inside a class when referencing itself.

$object-> is used from outside the class when referencing a specific object.

$class_name:: is used when referencing a static property or method of a specific class.


The differen between

$object->property;
Class::property;

is, that the first one access a object property, whereas the second one access a (static) class property. I really dont know, what you mean by "through new operator", because via new no property is accessable in any way, because new just creates a new object instance of a class. However, $this->property is exactly the same, as the first example above, but $this is only valid inside an object method and always references the object itself.

0

精彩评论

暂无评论...
验证码 换一张
取 消