【发布时间】:2020-02-20 21:54:11
【问题描述】:
抛出错误而不是检查是否设置了变量是否会造成很大的性能损失。
例如。 尝试捕获
public function getProperty(): int
{
try {
return $this->getDetail('some-detail');
} catch (Exception $e) {
return 0;
}
}
或者用isset
public function getProperty(): int
{
return isset($this->getDetail('some-detail')) ? $this->getDetail('some-detail') ? 0;
// or even $this->getDetail('some-detail') ?? 0; in php7
}
【问题讨论】:
标签: php