I have two functions, which has the same purpose, but I wrote it differently. The first one works fine, but the second one - doesn't work and I can't see the difference between them. Could someone explain me why the second one doesn't work properly?
public function getClientPhone() { if (is_null($this->client_id)) { return ''; } $phone = Client::getStaticClientPhone($this->client_id); if (is_null($phone)) { return '' ; } return $phone; }
public function getClientPhone() { $phone = Client::getStaticClientPhone($this->client_id); if ($this->client_id || $phone === null) { return ''; } return $phone; }
Change
if ($this->client_id || $phone === null) {
return '';
}
To
if ($this->client_id === null || $phone === null) {
return '';
}
Or
if (!$this->client_id || $phone === null) {
return '';
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.