Difference Between $this and self in PHP

What is the real difference between $this and self:: ?

A simple Google search will return several sites that show a definition such as this one:
“Use $this to refer to the current object. Use self to refer to the current class.”

But unless you are a PHP pro, you will need an example to illustrate this definition:

Here is an example to help you out:

class ycsoftware
{
static $stat = "static property";

public $pub='non static property';

public function test_this_self ()
{
print 'Trying to call the static member with this' . $this->stat;
// Nothing will be printed

print 'Trying to call the non static member with this' . $this->pub;
// OK 'non static property' will be printed

print 'Trying to call the static member with self' . self::stat;
// OK

print 'Trying to call the non static member with self' . self::pub
// ERROR

}
}
Use $this for non-static members

Use self:: for static members only

Reference
http://www.phpbuilder.com/board/showthread.php?t=10354489

Let's share thisShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn