Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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.

Christopher Hertel

December 20, 2017
Tweet

More Decks by Christopher Hertel

Other Decks in Programming

Transcript

  1. // 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
  2. Trick #4 Weird assignment // Insert Magic Code Here (10

    lines) $var = 'Hello!'; echo $var; Code World! Output
  3. Trick #5 Count on me // Insert Magic Code Here

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

    Here (6 lines) echo 'Hello'; echo 'World'; Code Hello PHP World Output
  5. Trick #7 Mad World // Insert Magic Code Here (3

    lines) echo 'Foobar'; echo PHP_EOL; echo 'Hello World'; Code dlroW olleH rabooF Output
  6. • replace „Insert Magic Code Here“ comments • no script

    termination return, exit, die, __halt_compiler, etc… • all lines executed on runtime • no additional eval RULES