The code is as follows: I use echo with a value. Why can't I get a value when I use return? The {code...} code is as follows:
I use echo with a value. Why can't I get a value if I use return?
class GoodNight implements IState { public function WriteCode(Work $w) { if($w->hour<22) { return Yii::t('yii','Good night'); }else{ $w->SetState(new GoodAtNight()); $w->WriteCode(); } } }
Reply content:
The code is as follows:
I use echo with a value. Why can't I get a value if I use return?
class GoodNight implements IState { public function WriteCode(Work $w) { if($w->hour<22) { return Yii::t('yii','Good night'); }else{ $w->SetState(new GoodAtNight()); $w->WriteCode(); } } }
Thank you for your invitation! Because you instantiate it and use it.returnThe returned value is not output, so no value is displayed. this is normal! If you directlyechoYou can see the output value after it is used out.
Class GoodNight implements IState {public function WriteCode (Work $ w) {if ($ w-> hour <22) {return Yii: t ('yii ', 'Good night ');} else {$ w-> SetState (new GoodAtNight (); echo $ w-> WriteCode (); // here echo has a value }}}