some practising

This commit is contained in:
Aleksandr Shelkovin 2025-01-24 15:20:07 +03:00
parent a4a6e36b3e
commit 0b4a887e7b
4 changed files with 95 additions and 1 deletions

View File

@ -112,3 +112,25 @@ echo"А теперь - {$objs[0]->getCount()} объекстов.<br/>";
$objs = [];
echo 'Под конец осталось - '. Counter::getCount() .' Объектов. <br/><br/>';
// require_once "minmax.php";
// $obj = new MinMax();
// echo $obj->min(43, 18, 5, 61, 23, 10, 56, 36);
// echo '<br/>';
// echo $obj->max(43, 18, 5, 61, 23);
// echo '<br/><br/>';
require_once "minmax_alter.php";
$obj = new MinMaxAlt();
echo $obj->min(43, 18, 5, 61, 23, 10, 56, 36);
echo '<br/>';
echo $obj->max(43, 18, 5, 61, 23);
echo '<br/><br/>';
require_once "minmax_static.php";
echo 'Вызов статического метода __callStatic() <br/><br/>';
echo MinMaxStat::min(43, 18, 5, 61, 23, 10, 56, 36);
echo '<br/>';
echo MinMaxStat::max(43, 18, 5, 61, 23);
echo '<br/><br/>';

View File

@ -0,0 +1,38 @@
<?php
class MinMax
{
public function __call(string $method, array $arr) : mixed
{
switch ($method) {
case 'min':
return $this->min($arr);
case 'max':
return $this->max($arr);
default:
return null;
}
}
private function min(array $arr) : mixed {
$result = $arr[0];
foreach ($arr as $value) {
if ($value < $result) {
$result = $value;
}
}
return $result;
}
private function max(array $arr) : mixed {
$result = $arr[0];
foreach ($arr as $value) {
if ($value > $result) {
$result = $value;
}
}
return $result;
}
}

View File

@ -0,0 +1,17 @@
<?php
class MinMaxAlt
{
public function __call(string $method, array $arr) : mixed
{
switch ($method) {
case 'min':
return min($arr);
case 'max':
return max($arr);
default:
return null;
}
}
}

View File

@ -0,0 +1,17 @@
<?php
class MinMaxStat
{
public static function __callStatic(string $method, array $arr) : mixed
{
switch ($method) {
case 'min':
return min($arr);
case 'max':
return max($arr);
default:
return null;
}
}
}