Skip to content

Instantly share code, notes, and snippets.

@i3or1s
Last active June 1, 2017 09:44
Show Gist options
  • Save i3or1s/2afc60855da5c482ce3d6854c5a71c63 to your computer and use it in GitHub Desktop.
Save i3or1s/2afc60855da5c482ce3d6854c5a71c63 to your computer and use it in GitHub Desktop.
Someone sometime ago asked me to print out both if and else. Print if and else
<?php
/* I have been asked to print out both if and else.
Put something instead of dots (...) so that the following code prints
string "TotallyImpossible" :
if (...) {
echo "Totally";
} else {
echo "Impossible";
}
*/
// Their answer to this was
if (!print_r("Totally")) {
echo "Totally";
} else {
echo "Impossible";
}
echo PHP_EOL;
// While on the other hand i got this "PHP magic" to work
$var = 1;
if(preg_match('#.+?(?={)\{(?P<if>.+?)(?=})#s', @array_pop(@explode("matches['else']", file_get_contents(__FILE__))), $matches) && eval($matches['if']) != NULL) {
echo "-- If true --".PHP_EOL;
$var++;
echo $var.PHP_EOL;
} else {
echo "-- If false --".PHP_EOL;
$var++;
echo $var.PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment