Pro Yearly is on sale from $80 to $50! »

PHP Magic Tricks

PHP Magic Tricks

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.

0bee6a2886272e60be8888ae48baf42d?s=128

Christopher Hertel

December 20, 2017
Tweet

Transcript

  1. PHP Magic Tricks Symfony User Group Berlin

  2. DISCLAIMER

  3. TRY THIS AT HOME

  4. DON‘T DO THIS TO YOUR PROJECT

  5. Trick #1 Twisted truth

  6. // Insert Magic Code Here var_dump(true === false); Code bool(true)

    Output Trick #1 Twisted truth
  7. Trick #2 Sum Sum Sum

  8. // Insert Magic Code Here var_dump(count($array), array_sum($array)); $array[0] = 1;

    $array[1] = 2; $array[2] = 3; var_dump(count($array), array_sum($array)); Code Trick #2 Sum Sum Sum
  9. int(3) int(0) int(3) int(9) Output Trick #2 Sum Sum Sum

  10. Trick #3 EvilVar

  11. // Insert Magic Code Here (4 lines) eval($$$$var); Code Hello

    World Output Trick #3 EvilVar
  12. Trick #4 Weird assignment

  13. Trick #4 Weird assignment // Insert Magic Code Here (10

    lines) $var = 'Hello!'; echo $var; Code World! Output
  14. Trick #5 Count on me

  15. Trick #5 Count on me // Insert Magic Code Here

    for ($i = 0; $i <= count($data); $i++){ $data++; } echo $data; Code Hello Output
  16. Trick #6 PHP in the middle

  17. Trick #6 PHP in the middle // Insert Magic Code

    Here (6 lines) echo 'Hello'; echo 'World'; Code Hello PHP World Output
  18. Trick #7 Mad World

  19. Trick #7 Mad World // Insert Magic Code Here (3

    lines) echo 'Foobar'; echo PHP_EOL; echo 'Hello World'; Code dlroW olleH rabooF Output
  20. RULES

  21. • replace „Insert Magic Code Here“ comments • no script

    termination return, exit, die, __halt_compiler, etc… • all lines executed on runtime • no additional eval RULES
  22. • Fork github.com/chr-hertel/php-magic-tricks • Your solutions as pull request •

    My solutions later tonight RULES
  23. CREDITS

  24. all anonymous PHP devs on 3V4L.org