For example :
class User {
private $sex = 1;
public function getSex() {
if($this->sex == 1)
return __('Male');
elseif($this->sex == 2)
return __('Female');
}
}
I believed that it’s better to not use gettext inside class, but I don’t know what can i do in this case.
In PHP it is acceptable to use global functions inside of objects — since most of the built in libraries are global functions anyway, it wouldn’t really make sense for this not to be the case. In this case, since you are using an external library, it actually strikes me as the most prudent approach.
As a side note:
__('Unknown');or__('Other');if(a == b){}elseif(a == c){}elseif(a ==d )..., you’re better off using theswitchstatement.