PHPでは、キーワード「$this」はクラスの自己参照として使用され、クラスの関数と変数を呼び出して使用するために使用できます。そしてここに例があります:
class ClassOne
{
// this is a property of this class
public $propertyOne;
// When the ClassOne is instantiated, the first method called is
// its constructor, which also is a method of the class
public function __construct($argumentOne)
{
// this key word used here to assign
// the argument to the class
$this->propertyOne = $argumentOne;
}
// this is a method of the class
function methodOne()
{
//this keyword also used here to use the value of variable $var1
return 'Method one print value for its '
. ' property $propertyOne: ' . $this->propertyOne;
}
}
また、parent::test() を呼び出すと、実際には CLASS B に関連付けられたテスト関数を呼び出します。これは、静的に呼び出しているためです。$this->test() と呼んでみると、B ではなく A が得られるはずです。