@Chiang
2020-03-12T14:51:21.000000Z
字数 723
阅读 584
面试题
2020-03
<?php
class Monitor
{
private $second; //秒数
private $eave; //预期值
public function __construct($n, $e)
{
$this->eave = $e;
$this->second = $n;
}
public function checkException(int $v): bool
{
static $num = 0; //调用次数
static $arr_v = []; // 指标集合
$eave = $this->eave;
$second = $this->second;
$arr_v[] = $v;
$max_v = max($arr_v);
$num++;
if(($max_v < $eave) && ($num > $second)){ //true 报警
$num = 0; //重置
return true;
}else if($num > $second){ //超时重置
$num = 0; //重置
return false;
}else{
return false;
}
}
}
$obj = new Monitor(5,8);
var_dump($obj->checkException(3));
var_dump($obj->checkException(9));
var_dump($obj->checkException(3));
var_dump($obj->checkException(3));
var_dump($obj->checkException(3));
var_dump($obj->checkException(3));
参考资料:
PHP static关键字的用法及注意点