note 31726 deleted from language.variables.scope by spic

From: Date: Thu, 01 May 2003 15:27:06 +0000
Subject: note 31726 deleted from language.variables.scope by spic
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-47354@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.

« previous php.notes (#47354) next »