0
Ошибка в практическом примере "Замена ссылки значением"
<?php
class Customer {
private $name;
private $birthDate;
public function getName() {
return $this->name;
}
public function getBirthDate() {
return $this->birthday;
}
public function setBirthDate(DateTime $birthDate) {
$this->birthDate = $birthDate;
}
private function __construct($name) {
$this->name = $name;
}
private static $instances = array();
public static function get($name) {
if (!isset($this->instances[$name])) {
$value = new Customer($name);
$this->instances[$name] = $value;
}
else {
$value = $this->instances[$name]
}
return value;
}
}
// Somewhere in client code
$john = Customer::get("John Smith");
$john->setBirthDate(new DateTime("1985-01-01"));
В статической функции get не может быть контекста $this, там должно быть self
Customer support service by UserEcho