The difference between self and this in php is: this is a pointer to the current object instance, it does not point to any other object or class; self points to the class itself, which means that self does not point to anything that has been instantiated Object, self is generally used to point to static variables in the class.
Difference analysis:
this
this is determined at the time of instantiation. who. Therefore, this is a pointer to the current object instance and does not point to any other object or class.
Example:
$this->name =$name; print( $this->name) $obj1 = new name("PBPHome");
self
self points to the class itself, that is, self does not point to any instantiated object. Generally, self is used to point to static variables in the class.
If we use static (usually keyword static) members in the class, we must also use self to call. Also note that using self to call static variables must use :: (field operator symbol).
Example:
$this->lastCount =++self::$firstCount
If you want to know more related knowledge, please visit php Chinese website.
The above is the detailed content of What is the difference between self and this in php. For more information, please follow other related articles on the PHP Chinese website!