oop koterov-simodyanov

This commit is contained in:
Aleksandr Shelkovin 2025-01-07 09:44:04 +03:00
parent ef67839659
commit 411e87503f
15 changed files with 172 additions and 1 deletions

View File

@ -0,0 +1,11 @@
<?php
$arr = [
0 => "Нулевой элемент",
"surname" => "Гейтс",
"name" => "Билл",
];
echo $arr['surname'];
$arr[1] = "Первый элемент";
$arr["name"] = "Вильям";
echo $arr['name'];

View File

@ -0,0 +1,10 @@
<?php
$date = new DateTime();
echo $date->format('d-m-Y H:i:s');
echo "<br/>";
echo gettype($date);
echo "<br/>";
echo get_class( $date );
echo "<br/>";
echo $date::class;

View File

@ -0,0 +1,111 @@
<?php
require 'point.php';
$point = new Point;
// var_dump($point->x);
$point->x = 5;
$point->y = 3.2;
echo '<pre>';
print_r($point);
echo '</pre>';
echo "<br/>";
echo $point->x;
echo "<br/>";
echo $point->y;
echo "<br/>";
echo gettype($point);
echo "<br/>";
echo get_class($point);
echo "<br/>";
echo "<br/>";
echo ($point ->x ** 2 + $point ->y ** 2) ** 0.5 . ' - Такое вот вычисление';
echo "<br/>";
// Уничтожение объекта
// unset($point);
// echo $point->x;
require_once('private_point.php');
$prpoint = new PrivatePoint;
$prpoint->x = 3;
echo $prpoint->x;
echo "<br/>";
echo gettype($prpoint);
echo "<br/>";
echo get_class($prpoint);
echo "<br/>";
echo "<br/>";
echo ($prpoint ->x ** 2 + $point ->y ** 2) ** 0.5 . ' - Такое вот вычисление';
echo "<br/>";
echo "<br/>";
require_once('readonly.php');
$obj = new Greating;
echo $obj->setter();
echo "<br/>";
echo "Hello $obj->hello";
echo "<br/>";
echo "<br/>";
require_once('readonly_construct.php');
$object = new GreatingConst();
echo "Hello construct $object->hello";
echo "<br/>";
echo gettype($object);
echo '<pre>';
print_r($object);
echo '</pre>';
echo "<br/>";
require_once("my_static.php");
echo "Статическая переменная: ". MyStatic::$staticvar;
echo "<br/>";
echo "<br/>";
// $first = $second = 1;
// $first = 3;
// echo $second;
// echo "<br/>";
// echo "<br/>";
// echo $first;
// echo "<br/>";
// echo "<br/>";
$first = new Point;
$first->x = 3;
$first->y = 3;
$second = $first;
$second->x = 5;
$second->y = 5;
echo "x: {$first->x}, y: {$first->y}";
echo "<br/>";
echo "<br/>";
$firstvar = 5;
$secondvar = &$firstvar;
$secondvar = 1;
echo $firstvar;
echo "<br/>";
echo "<br/>";
$secondclone = clone $first;
$secondclone->x = 9;
$secondclone->y = 9;
echo "Объект first до клонирования - x: {$first->x}, y: {$first->y}";
echo "<br/>";
echo "<br/>";
echo "Объект first после клонирования - x: {$secondclone->x}, y: {$secondclone->y}";

View File

@ -0,0 +1,5 @@
<?php
class MyStatic
{
public static $staticvar = 100;
}

View File

@ -0,0 +1,6 @@
<?php
class Point
{
public int|float $x;
public int|float $y;
}

View File

@ -0,0 +1,6 @@
<?php
class PrivatePoint {
public $x;
private $y = 3;
}

View File

@ -0,0 +1,8 @@
<?php
class Greating
{
public readonly string $hello;
public function setter() {
$this->hello = "PHP";
}
}

View File

@ -0,0 +1,8 @@
<?php
class GreatingConst
{
public readonly string $hello;
public function __construct() {
$this->hello = "PHP";
}
}

View File

@ -0,0 +1,6 @@
<?php
$name = "Имя пользователя";
$str = <<<'HTML_END'
Переменные PHP не будут мнтерполироваться: $name
HTML_END;
echo $str;

View File

@ -29,7 +29,7 @@ function render($tpl, $data)
return $content;
}
$value = ['box' => $box, 'title' => "God save the King!", 'body' => "Happy New Year!", 'auth' => true];
$value = ['box' => $box, 'title' => "God save the King!", 'body' => "Happy New Year!", 'auth' => false];
$portial = render('tpl_layout.php', $value);
echo $portial;

Binary file not shown.

Binary file not shown.

BIN
engine/upload/Oblaka_-.mp3 Normal file

Binary file not shown.