Scope of variables in php

From: Date: Thu, 03 Aug 2000 18:12:41 +0000
Subject: Scope of variables in php
Groups: php.general 
Request: Send a blank email to php-general+get-9994@lists.php.net to get a copy of this message
Hi, I'm having a little problem with variable scope in php. If I write code like this : if (some condition) { // myVar pops into existence here... $myVar = 42; ... echo $myVar; } echo $myVar; I get the first echo right, and the second echoes nothing. If I add global $myVar; [Some of the above] both echo instructions work. Is this correct (that is, php vars have block-scope) ? [And if this is correct how could I get wrong something so obvious for such a long time ? Am I getting back to clueless newbie status ? :)] Thanks in advance...

« previous php.general (#9994) next »