As a part of our joint #xmasmeetup we played a game called PHP Magic Tricks. Solutions were submitted on github.com/chr-hertel/php-magic-tricks.
PHP Magic TricksSymfony User Group Berlin
View Slide
DISCLAIMER
TRY THISAT HOME
DON‘T DO THISTO YOUR PROJECT
Trick #1Twisted truth
// Insert Magic Code Herevar_dump(true === false);Codebool(true)OutputTrick #1Twisted truth
Trick #2Sum Sum Sum
// Insert Magic Code Herevar_dump(count($array), array_sum($array));$array[0] = 1;$array[1] = 2;$array[2] = 3;var_dump(count($array), array_sum($array));CodeTrick #2Sum Sum Sum
int(3)int(0)int(3)int(9)OutputTrick #2Sum Sum Sum
Trick #3EvilVar
// Insert Magic Code Here (4 lines)eval($$$$var);CodeHello WorldOutputTrick #3EvilVar
Trick #4Weird assignment
Trick #4Weird assignment// Insert Magic Code Here (10 lines)$var = 'Hello!';echo $var;CodeWorld!Output
Trick #5Count on me
Trick #5Count on me// Insert Magic Code Herefor ($i = 0; $i <= count($data); $i++){$data++;}echo $data;CodeHelloOutput
Trick #6PHP in the middle
Trick #6PHP in the middle// Insert Magic Code Here (6 lines)echo 'Hello';echo 'World';CodeHello PHP WorldOutput
Trick #7Mad World
Trick #7Mad World// Insert Magic Code Here (3 lines)echo 'Foobar';echo PHP_EOL;echo 'Hello World';CodedlroW olleHrabooFOutput
RULES
• replace „Insert Magic Code Here“ comments• no script terminationreturn, exit, die, __halt_compiler, etc…• all lines executed on runtime• no additional evalRULES
• Fork github.com/chr-hertel/php-magic-tricks• Your solutions as pull request• My solutions later tonightRULES
CREDITS
all anonymousPHP devs on 3V4L.org