top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between $this and self in PHP?

0 votes
485 views
What is the difference between $this and self in PHP?
posted Mar 6, 2019 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

i think one of the deference of $this and $self is mention below:

PHP supports classes and other object-oriented constructs. Static functions and variables in PHP classes are not associated with any specific instance of the class (in other words, an object).
Instead, static functions and variables are associated with the class definition itself. In other words, all instances of a class share the same static variable. Within the context of a method (function) of a class, static variables and functions are accessed using self::. Other methods and variables are used in the context of an object (an instance) of a class, using this.

answer May 7, 2019 by Siddhi Patel
0 votes

"$this" refers to the instance of the class, that is correct. There is also something called static state, which is the same for all instances of that class. "self ::" is the accessor for those attributes and functions.

answer Nov 13, 2019 by Ifour Parth
...