Reputation: 205
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;
}
Upvotes: 1
Views: 33
Reputation: 10548
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 '';
}
Upvotes: 2