Skip to content

Commit 92555d8

Browse files
committed
Наследование. Ключевое слово "parent::"
1 parent 182334e commit 92555d8

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

app/App.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
<?php
22
namespace app;
33

4-
class App
4+
require __DIR__ . '/../vendor/liw/core/App.php';
5+
6+
use liw\core\App as Application;
7+
8+
/**
9+
* Class App
10+
* @package app
11+
*/
12+
class App extends Application
513
{
614
public function __construct()
715
{
8-
echo 'Создался новый экземпляр класса из папки "app/"';
16+
// Обращаемся к конструктору родительского класса
17+
parent::__construct();
18+
echo 'Создался новый экземпляр класса из папки "app/"<br>';
919
}
1020
}

vendor/liw/core/App.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ class App
88
{
99
public function __construct()
1010
{
11-
echo 'Создался новый экземпляр класса из папки "vendor/liw/core/"';
11+
echo 'Создался новый экземпляр класса из папки "vendor/liw/core/"<br>';
1212
}
1313
}

web/index.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,6 @@
44
* На этот файл будут переадресованы все запросы нашего сайта.
55
*/
66

7-
// Подключили файл из папки vendor
8-
require __DIR__ . '/../vendor/liw/core/App.php';
9-
10-
// создали новый объект класса из папки vendor
11-
$app = new liw\core\App();
12-
13-
14-
echo '<br>';
15-
16-
177
// Подключили файл из папки app
188
require __DIR__ . '/../app/App.php';
199

0 commit comments

Comments
 (0)