note 31726 added to language.variables.scope

From: Date: Thu, 01 May 2003 14:51:59 +0000
Subject: note 31726 added to language.variables.scope
Groups: php.notes 
Request: Send a blank email to php-notes+get-47352@lists.php.net to get a copy of this message
I'm probably missing something, but I don't see any discussion of variable scope and control structures. Anyways, old crabby Java developers (like myself) may be shocked to find that something like: <?PHP $condition = true; if ($condition) { $message = "Print Me"; } print $message; ?> works just fine in PHP. There is, apparently, no local scope within the braces of a control structure, unlike other languages. You need to be extremely careful when taking advantage of this feature, though. If your $condition is false, for example, you better be darn sure that your $message was not defined in the symbol table via some other means, especially through extraction of user input. Even with register_globals off, some other script you are including, or the framework you are building in may just go ahead and call extract($_REQUEST), and you'll end up with some unexpected and insecure behaviors. -- http://www.php.net/manual/en/language.variables.scope.php http://master.php.net/manage/user-notes.php?action=edit+31726 http://master.php.net/manage/user-notes.php?action=delete+31726 http://master.php.net/manage/user-notes.php?action=reject+31726

« previous php.notes (#47352) next »