-2018.05.03-
같은 결과로 이어지는 여러 조건이 있다. 이러한 모든 조건을 단일 표현식으로 통합한다.
class Security { private $_isHttps = true; private $_isAdmin = true; private $_totalLoginsPerDay = 19; . . . public function can_upload_file() { if($this->_isHttps == false) return 0; if($this->_isAdmin == false) return 0; if($this->_totalLoginsPerDay > 100) return 0; return 1; } } $login = new Security(); echo $login->can_upload_file();
class Security { private $_isHttps = true; private $_isAdmin = true; private $_totalLoginsPerDay = 19; . . . public function can_upload_file() { return $this->_isAdmin and $this->isHttps and ($this->totalLoginsPerDay <= 100); } } $login = new Security(); echo $login->can_upload_file();
단일 표현식으로 적용하였습니다.
※ 중괄로가없는if/then/else 문을 표시하지 말자. ( 중괄로를 생략하는 것은 나중에 명령문을 추가해야할 때 디버깅을 쉽게 시작할 수 있는방법)