Files
php_8/exceptions/destruct.php

41 lines
925 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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 />';