Hello World :)

Discussion in 'Programming' started by commandos, Nov 5, 2007.

  1. #1
    I found this question in a php book and i like it :) , wanted to share ... even if its in php its not really specific to php language ... it's a nice way to make your code very hard to understand ...


    <?php

    function myfunction($a, $b = true)
    {
    if($a && !$b) {
    echo "Hello, World!\n";
    }

    }


    $s = array (

    0 => "my",
    1 => "call",
    2 => '$function',
    3 => ' ',
    4 => "function",
    5 => '$a',
    6 => '$b',
    7 => 'a',
    8 => 'b',
    9 => ''

    );


    $a = true;
    $b = false;

    /* Group A */
    $name = $s[?].$s[?].$s[?].$s[?].$s[?].$s[?];
    /* Group B */
    $name(${$s[?]}, ${$s[?]});

    ?>


     
    commandos, Nov 5, 2007 IP
  2. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #2
    no one want to try ?

    come on its not that hard ...
     
    commandos, Nov 6, 2007 IP
  3. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #3
    You guys r lazy :p
     
    commandos, Nov 7, 2007 IP
  4. ste.richards

    ste.richards Guest

    Messages:
    46
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I got this far:

    function myfunction($a, $b = true)
    {
    if($a && !$b) {
    echo "Hello, World!\n";
    }
    }


    $s = array (

    0 => "my",
    1 => "call",
    2 => '$function',
    3 => ' ',
    4 => "function",
    5 => '$a',
    6 => '$b',
    7 => 'a',
    8 => 'b',
    9 => ''

    );


    $a = true;
    $b = false;

    /* Group A */
    $name = $s[9].$s[9].$s[9].$s[9].$s[0].$s[4];

    /* Group B */
    $name(${$s[1]}, ${$s[9]});


    I couldn't understand why it wasn't working though. Param 1 is set, and param 2 isn't set so it boggled me a bit.

    Took some thinking about those to even get that far, although it's really simple code it's a bit of a mind bender :)

    Thanks for posting it though
     
    ste.richards, Nov 7, 2007 IP
  5. ste.richards

    ste.richards Guest

    Messages:
    46
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I have the answer now :) Only through trial and improvement though

    $name = $s[9].$s[9].$s[9].$s[9].$s[0].$s[4];
    $name(${$s[7]}, ${$s[10]});
     
    ste.richards, Nov 7, 2007 IP
  6. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #6


    where did u get the 10 from ?
     
    commandos, Nov 7, 2007 IP
  7. Wisher

    Wisher Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    $name = $s[9].$s[9].$s[9].$s[9].$s[0].$s[4]; would result in $name = myfunction;
    $name(${$s[7]}, ${$s[8]}); would result in myfunction($a, $b);
    And myfunction($a, $b) (a.k.a. myfunction(true, false)) would result in "Hello, World!\n"

    Hope I got it.

    Best,
    Wisher
     
    Wisher, Apr 26, 2009 IP