note 81505 added to language.variables.scope
| From: | kevin at metalaxe dot com | Date: | Sat, 01 Mar 2008 18:56:28 +0000 |
| Subject: | note 81505 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136642@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Server IP: 209.41.74.194
Probable Submitter: 76.22.73.161
----
Manual Page -- http://www.php.net/manual/en/language.variables.scope.php
Edit -- https://master.php.net/note/edit/81505
Del: integrated -- https://master.php.net/note/delete/81505/integrated
Del: useless -- https://master.php.net/note/delete/81505/useless
Del: bad code -- https://master.php.net/note/delete/81505/bad+code
Del: spam -- https://master.php.net/note/delete/81505/spam
Del: non-english -- https://master.php.net/note/delete/81505/non-english
Del: in docs -- https://master.php.net/note/delete/81505/in+docs
Del: other reasons-- https://master.php.net/note/delete/81505
Reject -- https://master.php.net/note/reject/81505
Search -- https://master.php.net/manage/user-notes.php