some excercises
This commit is contained in:
parent
2ceedb75f5
commit
4da85dd434
@ -44,12 +44,12 @@ if (method_exists($point,'say')) {
|
|||||||
|
|
||||||
$greeting = new Greeting;
|
$greeting = new Greeting;
|
||||||
|
|
||||||
$greeting->x = 5;
|
// $greeting->x = 5;
|
||||||
if (method_exists($greeting,'x')) {
|
if (method_exists($greeting,'x')) {
|
||||||
echo $greeting->x;
|
echo $greeting->x;
|
||||||
}
|
}
|
||||||
|
|
||||||
$point->z = 5;
|
// $point->z = 5;
|
||||||
|
|
||||||
echo '<pre>';
|
echo '<pre>';
|
||||||
print_r($point->listVariables());
|
print_r($point->listVariables());
|
||||||
@ -63,4 +63,52 @@ echo "</br>";
|
|||||||
echo $rainbow->red;
|
echo $rainbow->red;
|
||||||
echo "</br>";
|
echo "</br>";
|
||||||
echo $rainbow->unknown;
|
echo $rainbow->unknown;
|
||||||
echo "</br>";
|
echo "</br>";
|
||||||
|
|
||||||
|
// require_once ('object.php');
|
||||||
|
|
||||||
|
// $objectConf = new Config;
|
||||||
|
|
||||||
|
// $objectConf->title = 'Название сайта';
|
||||||
|
// $objectConf->keywords = ['PHP', 'Phyton', 'Ruby', 'JavaScript' ];
|
||||||
|
// $objectConf->per_page = 20;
|
||||||
|
|
||||||
|
// echo '<pre>';
|
||||||
|
// print_r( $objectConf );
|
||||||
|
// echo '</pre>';
|
||||||
|
|
||||||
|
require_once ('settings.php');
|
||||||
|
|
||||||
|
$settings = new Settings;
|
||||||
|
|
||||||
|
$settings->title = 'Название сайта';
|
||||||
|
$settings->keywords = ['PHP', 'Phyton', 'Ruby', 'JavaScript' ];
|
||||||
|
$settings->per_page = 20;
|
||||||
|
|
||||||
|
echo '<pre>';
|
||||||
|
print_r( $settings );
|
||||||
|
echo '</pre>';
|
||||||
|
|
||||||
|
require_once ('static_greeting.php');
|
||||||
|
|
||||||
|
echo StaticGreeting::say('Kitty');
|
||||||
|
|
||||||
|
require_once ('page.php');
|
||||||
|
|
||||||
|
Page::render();
|
||||||
|
|
||||||
|
require_once ('static.php');
|
||||||
|
|
||||||
|
for ($objs = [], $i = 0; $i < 6; $i++) {
|
||||||
|
$objs[$i] = new Counter();
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "Сейчас существует {$objs[0]->getCount()} объектов.<br/>";
|
||||||
|
|
||||||
|
$objs[5] = null;
|
||||||
|
|
||||||
|
echo"А теперь - {$objs[0]->getCount()} объекстов.<br/>";
|
||||||
|
|
||||||
|
$objs = [];
|
||||||
|
|
||||||
|
echo 'Под конец осталось - '. Counter::getCount() .' Объектов. <br/><br/>';
|
5
Koterov-php-training/methods_of_classes/object.php
Normal file
5
Koterov-php-training/methods_of_classes/object.php
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Config {
|
||||||
|
|
||||||
|
}
|
23
Koterov-php-training/methods_of_classes/page.php
Normal file
23
Koterov-php-training/methods_of_classes/page.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Page
|
||||||
|
{
|
||||||
|
static $content = 'about<br/>';
|
||||||
|
|
||||||
|
public static function footer()
|
||||||
|
{
|
||||||
|
return 'footer<br/>';
|
||||||
|
}
|
||||||
|
public static function header()
|
||||||
|
{
|
||||||
|
return 'header<br/>';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function render()
|
||||||
|
{
|
||||||
|
echo self::header() .
|
||||||
|
self::$content .
|
||||||
|
self::footer();
|
||||||
|
echo '<br/>';
|
||||||
|
}
|
||||||
|
}
|
23
Koterov-php-training/methods_of_classes/settings.php
Normal file
23
Koterov-php-training/methods_of_classes/settings.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
class Settings
|
||||||
|
{
|
||||||
|
private array $properties;
|
||||||
|
|
||||||
|
public function __get(string $key): string
|
||||||
|
{
|
||||||
|
if (array_key_exists($key, $this->properties)) {
|
||||||
|
return $this->properties[$key];
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __set(string $key, $value): void
|
||||||
|
{
|
||||||
|
$this->properties[$key] = $value;
|
||||||
|
}
|
||||||
|
public function list(): array
|
||||||
|
{
|
||||||
|
return $this->properties;
|
||||||
|
}
|
||||||
|
}
|
25
Koterov-php-training/methods_of_classes/static.php
Normal file
25
Koterov-php-training/methods_of_classes/static.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Counter
|
||||||
|
{
|
||||||
|
private static $count = 0;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
self::$count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __destruct()
|
||||||
|
{
|
||||||
|
self::$count--;
|
||||||
|
}
|
||||||
|
public static function getCount(): int
|
||||||
|
{
|
||||||
|
return self::$count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class StaticGreeting
|
||||||
|
{
|
||||||
|
public static function say(string $who) :string
|
||||||
|
{
|
||||||
|
return "Hello, $who!</br></br>";
|
||||||
|
}
|
||||||
|
}
|
@ -2,5 +2,5 @@
|
|||||||
|
|
||||||
include_once ('tree.php');
|
include_once ('tree.php');
|
||||||
|
|
||||||
$cristmassTree = new Tree(50);
|
$cristmassTree = new Tree(25);
|
||||||
$cristmassTree->drawTree();
|
$cristmassTree->drawTree();
|
||||||
|
Loading…
Reference in New Issue
Block a user