Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- class User {
- public static $cont = 0;
- }
- class SuperUser extends User {
- public $role;
- public function __construct($role) {
- if (!$role) {
- throw new Exception('Не заданно свойство');
- }
- $this->role = $role;
- SuperUser::$cont++;
- }
- public function getInfo() {
- return "Hello, my role is " . $this->role . "<br/>";
- }
- }
- //исключение
- try {
- $me = new SuperUser('programmer');
- echo $me->getInfo();
- $you = new SuperUser();
- } catch (Exception $e) {
- echo 'Выброшено исключение: ', $e->getMessage(), "<br/>";
- }
- //подсчет объектов
- echo SuperUser::$cont;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment