why php cannot show variable in string template under some circumstances? -


thanks time in advance. newbie in php , encountered strange problem, @ least me strange. showing variable in string template. please see code below:

public function welcome() {     $data="everyone";     $b = $this->returntemplate();     $a = "<div>dear $data</div>"; } public function returntemplate() {     return "<div>dear $data</div>"; } 

i thought both $a , $b should same value <div>dear everyone</div> in fact $a while $b <div>dear </div>. puzzled me , wonder why? please explain me?

thanks in advance , feedback welcome!

you encountering 'variable scope'. have defined variable $data in welcome() function, not available anywhere outside of function. overcome this, either move out of function or pass parameter returntemplate function.

more info: http://php.net/manual/en/language.variables.scope.php


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -