Last active
August 29, 2015 14:03
-
-
Save kellegous/c86dc1176ab7017d5a85 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function chooseAmongTheseValues() { | |
foreach (func_get_args() as $arg) { | |
if (is_callable($arg)) { | |
$value = $arg(); | |
if ($value) { | |
return $value; | |
} | |
} else if ($arg) { | |
return $arg; | |
} | |
} | |
} | |
function get($key) { | |
if (array_key_exists($key, $_GET)) { | |
return $_GET[$key]; | |
} | |
} | |
echo chooseAmongTheseValues( | |
get('value'), | |
function() { return 'a value i looked up'; } | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@JamesXNelson - Strangely, this code has a limited version of eval since strings are callable if they match the name of a callable symbol. Which is, of course, a terrible idea. page.php?value=phpinfo will, for instance, get you a complete report on the php config.