note 114354 deleted from reserved.variables.globals by googleguy
| From: | googleguy@php.net | Date: | Wed, 12 Feb 2014 19:11:51 +0000 |
| Subject: | note 114354 deleted from reserved.variables.globals by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-198482@lists.php.net to get a copy of this message | ||
Note Submitter: themarlfox at yahoo dot com
----
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');
?>