-
Notifications
You must be signed in to change notification settings - Fork 0
/
53.php
53 lines (42 loc) · 1.32 KB
/
53.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
//Задача 53.1
// Сделайте класс User, в котором будут следующие свойства - name (имя),
// surname (фамилия), patronymic (отчество).
// Сделайте так, чтобы при выводе объекта через echo на
// экран выводилось ФИО пользователя (фамилия, имя, отчество через пробел).
class User
{
private $name;
private $age;
private $patronymic;
public function __construct($name, $age, $patronymic)
{
$this->name = $name;
$this->age = $age;
$this->patronymic = $patronymic;
}
// Реализуем указанный метод:
public function __toString()
{
return $this->name . ' ' . $this->age . ' ' . $this->patronymic;
}
}
$user = new User('Коля', 25, 'Николаевич ');
echo $user;
//Задача 53.2
// Не подсматривая в мой код, реализуйте такой же класс Arr.
class Arr
{
private $arr = [];
public function add($number)
{
$this->arr[] = $number;
return $this;
}
public function __toString()
{
return array_sum($this->arr);
}
}
$arr = new Arr;
echo $arr->add(1)->add(2)->add(3); // выведет 6