some practising
This commit is contained in:
parent
a4a6e36b3e
commit
0b4a887e7b
@ -112,3 +112,25 @@ echo"А теперь - {$objs[0]->getCount()} объекстов.<br/>";
|
|||||||
$objs = [];
|
$objs = [];
|
||||||
|
|
||||||
echo 'Под конец осталось - '. Counter::getCount() .' Объектов. <br/><br/>';
|
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/>';
|
||||||
|
38
Koterov-php-training/methods_of_classes/minmax.php
Normal file
38
Koterov-php-training/methods_of_classes/minmax.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
17
Koterov-php-training/methods_of_classes/minmax_alter.php
Normal file
17
Koterov-php-training/methods_of_classes/minmax_alter.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
17
Koterov-php-training/methods_of_classes/minmax_static.php
Normal file
17
Koterov-php-training/methods_of_classes/minmax_static.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user