Eğer bir sınıf oluşturmak zaman (birçok durumda) örnek değişkenler ve yöntemleri (aka. fonksiyonlar) var. Lütfen fonksiyonları onlarla ne istersen ne yapmak gerekir bu değişkenleri almak ve yapmak, böylece $ bu bu örnek değişkenleri erişir.
Meder örneğinden başka bir versiyonu:
class Person {
protected $name; //can't be accessed from outside the class
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
// this line creates an instance of the class Person setting "Jack" as $name.
// __construct() gets executed when you declare it within the class.
$jack = new Person("Jack");
echo $jack->getName();
Output:
Jack