class Student {
const TYPE_OCHN = 1;
const TYPE_ZAO = 2;
private $name;
private $sur;
private $birth;
private $type;
public function __construct($name,$sur,$type,$birth = null)
{ /// допустим, что тут валидация аргументов
/// ....
/// ....
$this->name = $name;
$this->sur = $sur;
$this->type = $type;
$this->birth = $birth;
}
/// какой-то код для работы дальше
}
# из всего примера нам важно, на какую именно форму обучения поступает student
$student1 = new Student('Alex1','Sur11',Student::TYPE_OCHN);
$student2 = new Student('Alex2','Sur12',Student::TYPE_OCHN);
$student3 = new Student('Alex3','Sur13',Student::TYPE_OCHN);
$student4 = new Student('Alex4','Sur14',Student::TYPE_OCHN);
$student5 = new Student('Alex5','Sur15',Student::TYPE_ZAO);
$student6 = new Student('Alex6','Sur16',Student::TYPE_OCHN);
$student7 = new Student('Alex7','Sur17',Student::TYPE_ZAO);
$student8 = new Student('Alex8','Sur18',Student::TYPE_OCHN);
class Student {
const TYPE_OCHN = 1;
const TYPE_ZAO = 2;
private $name;
private $sur;
private $birth;
private $type;
public function __construct($name,$sur,$type,$birth = null)
{ /// допустим, что тут валидация аргументов
/// .... /// ....
$this->name = $name;
$this->sur = $sur;
$this->type = $type;
$this->birth = $birth;
}
# приём вспомогательного конструктора
public static function createOchn($name,$sur,$birth = null)
{
return new self($name,$sur,self::TYPE_OCHN,$birth);
}
public static function createZao($name,$sur,$birth = null)
{
return new self($name,$sur,self::TYPE_ZAO,$birth);
}
/// какой-то код для работы дальше
}
# это воистину гениально!
$student1 = Student::createOchn('Alex1','Sur11');
$student2 = Student::createOchn('Alex2','Sur11');
$student3 = Student::createOchn('Alex3','Sur11');
$student4 = Student::createZao('Alex4','Sur11');
$student1 = Student::createOchn('Alex5','Sur11');
$student1 = Student::createZao('Alex6','Sur11');
$student1 = Student::createZao('Alex7','Sur11');
$student1 = Student::createOchn('Alex8','Sur11');
$student1 = Student::createOchn('Alex9','Sur11');