note 81505 deleted from language.variables.scope by danbrown

From: Date: Mon, 18 May 2009 01:30:29 +0000
Subject: note 81505 deleted from language.variables.scope by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155547@lists.php.net to get a copy of this message
Note Submitter: kevin at metalaxe dot com ---- in reply to: "I hope some1 reading and understanding here creates an example about this. Im so lazy at doing that." -- pepesantillan at gmail dot com Though not exactly your example, I don't like functions declared within functions. So this is, effectively, the same result you were explaining :P <?php ini_set( 'display_errors', true ); error_reporting( E_ALL | E_STRICT ); /** * This is already in the global scope **/ $global_var1 = 'I\'m global!'; // Call a function some_function(); //Note that $localvar is NOT in the global scope //Undefined variable Error var_dump( $localvar ); function some_function() { /** * Now we are in function scope. Global scope vars can't be accessed here **/ // Undefined variable error (for $global_var1) $localvar = $global_var1; //Gonna call another function and send $localvar as ref another_function( $localvar ); // Note that $localvar has a value here... var_dump( $localvar ); } function another_function( &$input ) { // Get the global global $global_var1; // Assign it to $input which is referenced to $localvar in the other function $input = $global_var1; } ?>

« previous php.notes (#155547) next »