News for hackers. Stuff that matters.
Re:Code that is valid in both PHP and Java, and produces the... by kleer001 on Wednesday August 31, 2016 @11:39PM (#12402960)
Yup, you can do that with just about any set of languages, right?
Re:Code that is valid in both PHP and Java, and produces the... by ygra on Thursday September 01, 2016 @01:29AM (#12403277)
The trick here relies mostly on comments that are valid for one language, but not the other (abusing Java's Unicode preprocessing). There are language pairs that offer no provision at all for embedding parts of code that another language won't see or misinterpret. E.g., I haven't been able to write a batch file that also works as a PowerShell script yet, although you can write a batch file that doubles as a VB script through clever use of a conditional jump.
Re:Code that is valid in both PHP and Java, and produces the... by kleer001 on Saturday September 03, 2016 @02:35PM (#12420434)
Oooh, right. So, I guess there's some pairs that are incompatible. Hmm :(

Maybe it also work for computationally equivalent (simulation/emulation) math where you're decompiling the machine language into a stream of logical NORs or such. That might connect more languages.

Re:Code that is valid in both PHP and Java, and produces the... by ryanlm on Wednesday August 31, 2016 @11:46PM (#12402980)
No, but another one you can do it in is PHP and JavaScript

    function isEven($number) {
        return $number % 2 == 0;
    }
That's actually valid PHP code and JavaScript. But I think you'll need to use eval on that in the PHP vm because it won't have the `<?php`
Re:Code that is valid in both PHP and Java, and produces the... by mikeryan on Thursday September 01, 2016 @12:01AM (#12403023)
You can use the same trick used here of hiding the PHP tags behind the comments /*<?php
Re:Code that is valid in both PHP and Java, and produces the... by ivanca on Thursday September 01, 2016 @01:35AM (#12403293)
Actually that trick creates some residual garbage (the slash and the asterisk would be printed in PHP)

A way to avoid this is to use the HTML comment notation, JavaScript just ignores it (until end of line), so just:

    <!-- <?php echo "-->";