note 87134 rejected from language.variables.scope by danbrown

From: Date: Thu, 20 Nov 2008 16:31:46 +0000
Subject: note 87134 rejected from language.variables.scope by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-146772@lists.php.net to get a copy of this message
Note Submitter: mark at markfiend dot com ---- I'm slightly confused by another developer's script declaring global variables while already in the global scope; it won't work! <?php global $a; $a = 10; echo $a . '-'; function something($input) { echo $a . '-'; $a = $input * 2; echo $a . '-'; } something(3); echo $a; ?> Outputs (as I expected) 10--6-10 whereas... <?php $a = 10; echo $a . '-'; function something($input) { global $a; echo $a . '-'; $a = $input * 2; echo $a . '-'; } something(3); echo $a; ?> Outputs (again as expected) 10-10-6-6

« previous php.notes (#146772) next »