Skip to content

Instantly share code, notes, and snippets.

@kellegous
Last active August 29, 2015 14:03
Show Gist options
  • Save kellegous/c86dc1176ab7017d5a85 to your computer and use it in GitHub Desktop.
Save kellegous/c86dc1176ab7017d5a85 to your computer and use it in GitHub Desktop.
<?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'; }
);
@JamesXNelson
Copy link

Now, all you need is a little eval() in there, and you've got yourself some Grade A secure PHP!

@kellegous
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment