note 114354 added to reserved.variables.globals

From: Date: Wed, 12 Feb 2014 07:32:28 +0000
Subject: note 114354 added to reserved.variables.globals
Groups: php.notes 
Request: Send a blank email to php-notes+get-198463@lists.php.net to get a copy of this message
I use $GLOBALS for calling variables that were declared within if statements. It saves me from writing an else statement to declare the variable as null if the condition wasn't met. <?php class Input { public static function returnvar($variablename) { if(isset($GLOBALS[$variablename])) { return $GLOBALS[$variablename]; } return null; } } if(4 == 1) { $foo = 'declaring a variable based on a condition that was false'; } echo Input::returnvar('foo'); ?> ---- Server IP: 72.52.91.14 Probable Submitter: 72.52.91.14 ---- Manual Page -- http://php.net/manual/en/reserved.variables.globals.php Edit -- https://master.php.net/note/edit/114354 Del: integrated -- https://master.php.net/note/delete/114354/integrated Del: useless -- https://master.php.net/note/delete/114354/useless Del: bad code -- https://master.php.net/note/delete/114354/bad+code Del: spam -- https://master.php.net/note/delete/114354/spam Del: non-english -- https://master.php.net/note/delete/114354/non-english Del: in docs -- https://master.php.net/note/delete/114354/in+docs Del: other reasons-- https://master.php.net/note/delete/114354 Reject -- https://master.php.net/note/reject/114354 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#198463) next »