I have defined a few constants like this:
define("TITLE_2","Yahoo");
define("TITLE_3","Google");
Next, I want to get the constant through a function.
public function title($id) {
return TITLE_.$id;
}
Idea, I can call $this->title(2) to get Yahoo and $this->title(3) to get Google. However, it is not working. I am getting TITLE_2 or TITLE_3 in place of Yahoo or Google.
Help? Thanks.
TITLE_1is as meaningless asTITLE_2. Passing 1 or 2 togetTitle()is not helping anyone to understand what these Magic Numbers stand for. Either you want to use Constants, then access them directly withTITLE_YAHOOorTITLE_GOOGLEor use Contant Methods instead of the Constants, e.g.getTitleForYahoo()andgetTitleForGoogle()where those return the strings. But not that mishmash.