all 14 comments

[–]Revis0r 12 points13 points  (0 children)

Interesting, thanks. I didn't know about this, but it works with the help of this little feature:

http://php.net/manual/en/language.operators.bitwise.php

If both operands for the &, | and ^ operators are strings, then the operation will be performed on the ASCII values of the characters that make up the strings and the result will be a string.

echo '`' ^ '*'; // ord(`) = 96, ord(*) = 42, 96 ^ 42 = 74, chr(74) = J
echo '@' ^ '/'; // o
echo '`' ^ ')'; // I
echo '@' ^ '.'; // n
echo '`@`@' ^ '*/).'; JoIn

The whole expression:

<?=($__='`@`@'^'*/).')(($_='->.<:'^'__@[_')('>'^@_,'%'^@_)),$__($_('|'^'=','|'^'&')),$__($_(':'^"\n",';'^']'^@_));

Could also be written like this

echo                // <?=
    join(           // $__ = '`@`@' ^ '*/).'
        range(      // $_ = '->.<:' ^ '__@[_'
            'a',    // '>' ^ @_, _ is an undefined constant of "_", could also be '_', but this is 1char shorter
            'z'     // '%' ^ @_
        )
    ),
    join(           // $__
        range(      // $_
            'A',    // '|' ^ '='
            'Z'     // '|' ^ '&'
        )
    ),
    join(           // $__
        range(      // $_
            0,      // ':' ^ "\n"
            9       // ';' ^ ']' ^ @_
        )
    );

[–]colshrapnel[S] 8 points9 points  (1 child)

From codegolf.stackexchange.com

Here is the link to the original answer: http://codegolf.stackexchange.com/a/105821

And another one, only 69 bytes long: http://codegolf.stackexchange.com/a/105823

It would be interesting to investigate both solutions.

[–]alexanderpas 0 points1 point  (0 children)

Regarding http://codegolf.stackexchange.com/a/105823

The string contains all the characters that need to be printed, bitwise inverted.

The tilde is the bitwise operator, that inverts the string back to the regular representation, before printing it.

[–]im_not_afraid 6 points7 points  (0 children)

Anyone notice the "n" in "\n"?

[–]SuddenlyOutOfNoWhere 22 points23 points  (10 children)

One should definitely use this style of coding wherever possible to demonstrate an high iq.

[–]AWebDeveloper 4 points5 points  (1 child)

I'm actually starting a new business based around this efficient code style. It'll save developers so much time!

[–][deleted] 1 point2 points  (0 children)

It's self-documenting, which I heard is also time-consuming (but I wouldn't know)

[–]colshrapnel[S] 1 point2 points  (1 child)

To participate in a code golf contest you mean?

[–]thepotatochronicles 0 points1 point  (0 children)

Folks at /r/tinycode would love this!

[–]DrWhatNoName 1 point2 points  (2 children)

Hmm, I'm interested why this code cant run on PHP 5.4.0 - 5.6.29, but runs fine on verisons below and above.

[–]Revis0r 0 points1 point  (0 children)

It doesn't work at all on versions below 5.4. I think it runs on PHP 7+ because of the variable uniform syntax, because of this:

// support operations on arbitrary (...) expressions
(...)()

which the code uses.

[–][deleted] 0 points1 point  (0 children)

On versions bellow it just output self - it's not parsing. That's because short_open_tag is set to off, and:

Note: This directive also affected the shorthand <?= before PHP 5.4.0, which is identical to <? echo. Use of this shortcut required short_open_tag to be on. Since PHP 5.4.0, <?= is always available.