Access local variable in function from outside function (PHP) -


is there way achieve following in php, or not allowed? (see commented line below)

function outside() {     $variable = 'some value';     inside(); }  function inside() {     // possible access $variable here without passing argument? } 

its not possible. if $variable global variable have access global keyword. in function. can not access it.

it can achieved setting global variable by$globals array though. again, utilizing global context.

function outside() {     $globals['variable'] = 'some value';     inside(); }  function inside() {         global $variable;         echo $variable; } 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -