-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathdestruct.php
More file actions
41 lines (36 loc) · 926 Bytes
/
destruct.php
File metadata and controls
41 lines (36 loc) · 926 Bytes
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
<?php
// Класс, комментирующий операции со своим объектом
class Orator
{
private $name;
function __construct($name)
{
$this->name = $name;
echo "Создан объект {$this->name}<br />";
}
function __destruct()
{
echo "Уничтожен объект {$this->name}<br />";
}
}
function outer()
{
$obj = new Orator(__METHOD__);
inner();
}
function inner()
{
$obj = new Orator(__METHOD__);
echo 'Внимание, вбрасывание!<br />';
throw new Exception('Hello!');
}
// Основная программа
echo 'Начало программы<br />';
try {
echo 'Начало try-блока<br />';
outer();
echo 'Конец try-блока<br />';
} catch (Exception $e) {
echo "Исключение: {$e->getMessage()}<br />";
}
echo 'Конец программы<br />';