Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This snippet of code is syntactically valid in both PHP and Java, and produces the same output in both.
/*<?php
//*/public class PhpJava { public static void main(String[] args) { System.out.printf("/*%s",
//\u000A\u002F\u002A
class PhpJava {
static function main() {
echo(//\u000A\u002A\u002F
"Hello World!");
}}
//\u000A\u002F\u002A
PhpJava::main();
//\u000A\u002A\u002F
/*<?php
//*/public class PhpJava { public static void main(String[] args) { System.out.printf("/*%s",
//\u000A\u002F\u002A
class PhpJava {
static function main() {
echo(//\u000A\u002A\u002F
"Hello World!");
}}
//\u000A\u002F\u002A
PhpJava::main();
//\u000A\u002A\u002F
@mtib

This comment has been minimized.

Copy link

commented Aug 31, 2016

👍

@stanier

This comment has been minimized.

Copy link

commented Aug 31, 2016

You were so preoccupied with whether or not you could, you didn't stop to think if you should

@forairan

This comment has been minimized.

Copy link
Owner Author

commented Aug 31, 2016

;)

@brndwgn

This comment has been minimized.

Copy link

commented Aug 31, 2016

Excellent work.

@Jbithell

This comment has been minimized.

Copy link

commented Aug 31, 2016

Love it

@JesterMan

This comment has been minimized.

Copy link

commented Aug 31, 2016

But now we'll never know if Schrodinger's computer is running php or java...

@velowebb

This comment has been minimized.

Copy link

commented Aug 31, 2016

I hope you die in a fire of a 1000 java compilers.

@ematta

This comment has been minimized.

Copy link

commented Aug 31, 2016

I feel like this will be used for evil in the near future. You flew too close to the sun, Icarus...

@djneo92nl

This comment has been minimized.

Copy link

commented Aug 31, 2016

Valid but it will throw a warning on calling a non static function, static

@fakingfantastic

This comment has been minimized.

Copy link

commented Aug 31, 2016

Really feel like you missed an opportunity to name this file PhpJava.java.php

@craig-davis

This comment has been minimized.

Copy link

commented Aug 31, 2016

I'd like to suggest we call this new language Phava.

@NetOperatorWibby

This comment has been minimized.

Copy link

commented Aug 31, 2016

+1 for Phava

@Skintillion

This comment has been minimized.

Copy link

commented Aug 31, 2016

Creative for sure.

@JohnMurray

This comment has been minimized.

Copy link

commented Aug 31, 2016

This is fantastic.

@Immortalizd

This comment has been minimized.

Copy link

commented Aug 31, 2016

There is no ?>, which is bugging the shit out of me.

@cpmiller

This comment has been minimized.

Copy link

commented Aug 31, 2016

+1 for Phava.

I further suggest that reusable libraries of code in this new ecosystem be referred to as "Phava Beans".

@EliW

This comment has been minimized.

Copy link

commented Aug 31, 2016

@Immortalizd : That would be on purpose. It's standard best practice at the moment to leave the ?> off the bottom of any PHP file. (It's not needed, and by leaving it off you can't accidentally end up with a random space or CR after it, causing output that was unintended.

@lcashdol

This comment has been minimized.

Copy link

commented Aug 31, 2016

Gah!

@ReneFroger

This comment has been minimized.

Copy link

commented Aug 31, 2016

Genius.

Now we're heading towards files which will compile and interpret in all languages, to rule 'em all. No language wars anymore.

@tenmilez

This comment has been minimized.

Copy link

commented Sep 1, 2016

+1 for Phava because PhavaEE you'd have phava beans for your hannibal code that reflectively consumes other classes of the same type.

@nygeek

This comment has been minimized.

Copy link

commented Sep 1, 2016

Another triumph of Banach's Fixed Point Theorem.

@vuongggggg

This comment has been minimized.

Copy link

commented Sep 1, 2016

really nice!

@leighmcculloch

This comment has been minimized.

Copy link

commented Sep 1, 2016

+1 for Pharva.

@akshaysmurthy

This comment has been minimized.

Copy link

commented Sep 1, 2016

Excellent 😄

@aj-jaswanth

This comment has been minimized.

Copy link

commented Sep 1, 2016

👍

@philipbroadway

This comment has been minimized.

Copy link

commented Sep 1, 2016

+1 for Pharva

@f00stx

This comment has been minimized.

Copy link

commented Sep 1, 2016

"I am become Death, the destroyer of worlds" - @forairan (probably).

@Andrewpk

This comment has been minimized.

Copy link

commented Sep 1, 2016

There's no ?> because you don't close php tags unless you're nesting php in html. http://www.php-fig.org/psr/psr-2/#2-2-files

@pmelson

This comment has been minimized.

Copy link

commented Sep 1, 2016

If you implement multi-object classes, will they be PhavaBeans? :-D

@geonnave

This comment has been minimized.

Copy link

commented Sep 1, 2016

Why not phap ?

@franciscop

This comment has been minimized.

Copy link

commented Sep 1, 2016

You were so preoccupied with whether or not you could, you didn't stop to think if you should

😂 😂

@ralphstodomingo

This comment has been minimized.

Copy link

commented Sep 1, 2016

You've crossed the line, dear brother. Now what will happen to all of us?

@mrxinu

This comment has been minimized.

Copy link

commented Sep 1, 2016

I cannot wait to beat PHP slingers with this one.

@sangupta

This comment has been minimized.

Copy link

commented Sep 1, 2016

👍

@quaj

This comment has been minimized.

Copy link

commented Sep 1, 2016

👍

@tcper

This comment has been minimized.

Copy link

commented Sep 1, 2016

👍

@supsep

This comment has been minimized.

Copy link

commented Sep 1, 2016

Legendary

@awebdeveloper

This comment has been minimized.

Copy link

commented Sep 1, 2016

wow

@csbenk

This comment has been minimized.

Copy link

commented Sep 1, 2016

👍

@jv2222

This comment has been minimized.

Copy link

commented Sep 1, 2016

It's helpful never to use ?> for the end of a file because then you never get the whitespace cookie header problem. And after a while it just seems cleaner.

@Krasavchik

This comment has been minimized.

Copy link

commented Sep 1, 2016

creative !

@aurmil

This comment has been minimized.

Copy link

commented Sep 1, 2016

👍
achievment unlocked?

@patriziobruno

This comment has been minimized.

Copy link

commented Sep 1, 2016

+1 for Phava

... especially if you consider that in the Tuscan dialect it has a special meaning ;D

@napolux

This comment has been minimized.

Copy link

commented Sep 1, 2016

Confused computer is confused.

@qoomon

This comment has been minimized.

Copy link

commented Sep 1, 2016

aha

@jeremy-cc

This comment has been minimized.

Copy link

commented Sep 1, 2016

H̡͕͕̲̩̞̫̗̅̃̓ͩ͜ͅẹ̺̣͎̯͔̗̜̈́ͪ ͍̻̫͉̤̥̌ͣ͒̀͟w̨̫̹͋ͭ̈ͦͮ͆̏̀͠h̵̖̮̱̤̣͈̉ͣ̑͆̋̏ô͕͑̀͂ͣ͢ ̿ͩ͜҉̣͕͙̪͚̲̻W̤̝͍̐ͬ̌̚̚͡a̢̰̗̋̿́̃ͪ̃͐ͯͨ͘i̧̧̠̩̤̝͐̊̆̂ͥ̓ͫ̿ͫt̲̫̞̞̊̉̐͒̇̈́̚͠s̶̴͔̖̦̟̟͍͓̫̐̃ͤͣ ̵̲͙̤̪̈ͮ̿ͪͪͧ̆ͅB̼͚̦͖̞̆ͦ̆͑̀͟e̪̦̣̱̯͖̟͋̔͗͗ͥ̿h̹̫̖̀ͤ̈͐̎̈́͋ï̧̛̘̜̥̩͈̥̒̅n̲̹̟̤̺̳͂͒͆ͥ̀͑͋̔͢͜ď̶̺͉͉̟̟̬̪̃ͤ́͆̒̊͝ ̶̛͕̭̇ͫͣ́́̚T̰͈͓͕͉̦̫́̂̓̔́͘͢͟ȟ̶̰̙ͨe̠ͧ̅̍̈́ͩ ̧̛͈̙ͣ̑͛̍͋̔́̚W̨͕̞̲͊̈ͦa͓̣̻͉͍̠̲̫͓ͣͣ͊͗̾l̃͆҉̺̣̩͕͖͔̜̻̬͢l͐̊ͬ̑͆̊̈̅͡͏̪̘͍.̧̼̰̝̳̫̫́ͧͧ́̓̐ͭͯ̆́

@koliber

This comment has been minimized.

Copy link

commented Sep 1, 2016

Please, please, please build a full web application server like this. So you know, no single point of failure :). Enterprise customers would be thrilled.

@kgdinesh

This comment has been minimized.

Copy link

commented Sep 1, 2016

lol

@dland

This comment has been minimized.

Copy link

commented Sep 1, 2016

Why not phap ?

+1

@gmaxwell

This comment has been minimized.

Copy link

commented Sep 1, 2016

Those seeking to name the language are getting ahead of themselves; this is just printing a string. Some more work would be needed to demonstrate this can perform arbitrary computation before calling it a language. [... then someone could produce a (say) javascript interpreter with it...]

@jjjjjjjjjjjjjjjjjjjj

This comment has been minimized.

Copy link

commented Sep 1, 2016

👍

@Kali187

This comment has been minimized.

Copy link

commented Sep 1, 2016

PHava
screen shot 2016-09-01 at 09 45 05

@blater

This comment has been minimized.

Copy link

commented Sep 1, 2016

phava

@mpragliola

This comment has been minimized.

Copy link

commented Sep 1, 2016

Actually, Phava can be a bit rude and sexually explicit for the people of Tuscany (Italy).
Besides this minor annoyance, nice name.

@unreal4u

This comment has been minimized.

Copy link

commented Sep 1, 2016

Nice one, there are however some strict notices to be taken care of: https://3v4l.org/0SDi4

@kapv89

This comment has been minimized.

Copy link

commented Sep 1, 2016

@gmaxwell, you don't get it

@hsyhhssyy

This comment has been minimized.

Copy link

commented Sep 1, 2016

I hava created JavaCSharp in the same way~~
JavaCSharp
A code that is valid in Java and C# (Tested in VS2015)

@COil

This comment has been minimized.

Copy link

commented Sep 1, 2016

Can you do it for 3 languages ? 🎅

@hiryuken

This comment has been minimized.

Copy link

commented Sep 1, 2016

Being from Tuscany (Italy), +1 for Phava

@brzuchal

This comment has been minimized.

Copy link

commented Sep 1, 2016

Like that Phava 👍

@razki

This comment has been minimized.

Copy link

commented Sep 1, 2016

+1

@bmanojkumar

This comment has been minimized.

Copy link

commented Sep 1, 2016

Phjava..good one

@valugi

This comment has been minimized.

Copy link

commented Sep 1, 2016

syntactically valid but horrible looking.

@davidstanley01

This comment has been minimized.

Copy link

commented Sep 1, 2016

That's an abomination... I'm pretty sure the Ghostbusters warned us of this

@franciskim

This comment has been minimized.

Copy link

commented Sep 1, 2016

So who's going to do a to-do app in this format? :D

@guillaumebort

This comment has been minimized.

Copy link

commented Sep 1, 2016

$ time php PhpJava.java
/*Hello World!
real    0m0.079s
user    0m0.068s
sys 0m0.009s
$ time java PhpJava
/*Hello World!
real    0m0.113s
user    0m0.094s
sys 0m0.025s

I always knew that PHP is faster than Java.

@nulligor

This comment has been minimized.

Copy link

commented Sep 1, 2016

+1 for Phava

@MichaelZaporozhets

This comment has been minimized.

Copy link

commented Sep 1, 2016

This is fantastic 👍

@roshimon

This comment has been minimized.

Copy link

commented Sep 1, 2016

Compiling Java code throwing me errors :(

@rafaelcn

This comment has been minimized.

Copy link

commented Sep 1, 2016

Holy crap, this makes me weep. So ugly 😭

@ryukinix

This comment has been minimized.

Copy link

commented Sep 1, 2016

Urgh. Why this shit even exists? Oh boy, some hacker could erase all the compilers and source of Java and PHP... :(. Our World will be a better a please after this.

@lennynyktyk

This comment has been minimized.

Copy link

commented Sep 1, 2016

I for one welcome our new Phava bean overlords!

@n3dst4

This comment has been minimized.

Copy link

commented Sep 1, 2016

Some people just want to watch "Hello, world" burn.

@ryukinix

This comment has been minimized.

Copy link

commented Sep 1, 2016

nojo

@tomaszpolska

This comment has been minimized.

Copy link

commented Sep 1, 2016

Cool 👍

@isotopp

This comment has been minimized.

Copy link

commented Sep 1, 2016

https://github.com/mauke/poly.poly
Please integrate with this.

@soyuka

This comment has been minimized.

Copy link

commented Sep 1, 2016

You were so preoccupied with whether or not you could, you didn't stop to think if you should

😆

@nervoustwit

This comment has been minimized.

Copy link

commented Sep 1, 2016

You were so preoccupied with whether or not you could, you didn't stop to think if you should

+1

@johnhunt

This comment has been minimized.

Copy link

commented Sep 1, 2016

You were so preoccupied with whether or not you could, you didn't stop to think if you should

Hands down best comment ever.

@simonhamp

This comment has been minimized.

Copy link

commented Sep 1, 2016

Same code, same output? Not REALLY. The execution paths are very different, so the compiler/parser isn't seeing the same code... and the output for the PHP example will actually be:

/*Hello World!
@Incognito

This comment has been minimized.

Copy link

commented Sep 1, 2016

But does it run in HHVM?

@forairan

This comment has been minimized.

Copy link
Owner Author

commented Sep 1, 2016

@simonhamp - Yes, different execution paths, but that's the nature of this. It's a joke.
And in fact, if you read the code, you'd see that the Java example is adjusted to account for the extra /*. ;)

The point is that one source file is syntactically valid in two different languages, while producing the same output. Of course they won't have the same execution path.

@alexmoreno

This comment has been minimized.

Copy link

commented Sep 1, 2016

image

@raul-gracia

This comment has been minimized.

Copy link

commented Sep 1, 2016

👍 for Phava and Phava Beans

@boberlla

This comment has been minimized.

Copy link

commented Sep 1, 2016

I am going to ditch all of our Java code now because PHava is faster.
phava

@hamdrew

This comment has been minimized.

Copy link

commented Sep 1, 2016

What is the purpose of all the //\u000A\u002F\u002A comments?

@EvgenyOrekhov

This comment has been minimized.

Copy link

commented Sep 1, 2016

@forairan PHP 7 result is

/*
Deprecated: Non-static method PhpJava::main() should not be called statically in PhpJava.php on line 10
Hello World!

To avoid this function main() { should be changed to static function main() {.

@princessruthie

This comment has been minimized.

Copy link

commented Sep 1, 2016

Now we can all just get along! Kumbaya~~

@nicolasdanelon

This comment has been minimized.

Copy link

commented Sep 1, 2016

asdkl

@gburges

This comment has been minimized.

@hendrikebbers

This comment has been minimized.

Copy link

commented Sep 1, 2016

😱

@Alanaktion

This comment has been minimized.

Copy link

commented Sep 1, 2016

Please, please, please build a full web application server like this. So you know, no single point of failure :). Enterprise customers would be thrilled.

Oh please no 😢 The problem is this would probably convince most PHBs.

@bestform

This comment has been minimized.

Copy link

commented Sep 1, 2016

No

@forairan

This comment has been minimized.

Copy link
Owner Author

commented Sep 1, 2016

@EvgenyOrekhov Fixed, thanks. I was too focused on making it work with both to focus on making it work with one ;)

@forairan

This comment has been minimized.

Copy link
Owner Author

commented Sep 1, 2016

@hamdrew There's good explanations on Reddit here and here. Essentially, it's a hacky way to tell Java to start/end a multiline comment, without triggering PHP to do the same.

@kme1018

This comment has been minimized.

Copy link

commented Sep 1, 2016

image

@zz

This comment has been minimized.

Copy link

commented Sep 1, 2016

PHP is the king of JAVA.

@jeantil

This comment has been minimized.

Copy link

commented Sep 1, 2016

not bad, next step is to beat the polyglot quine at http://shinh.skr.jp/obf/

@travispwingo

This comment has been minimized.

Copy link

commented Sep 1, 2016

Nice!

@eleakin

This comment has been minimized.

Copy link

commented Sep 1, 2016

Love it!

@tom-dalton-fanduel

This comment has been minimized.

Copy link

commented Sep 1, 2016

Do not want

@avaleriani

This comment has been minimized.

Copy link

commented Sep 1, 2016

Phava +1

@atkawa7

This comment has been minimized.

Copy link

commented Sep 1, 2016

Phava +1

@Bankq

This comment has been minimized.

Copy link

commented Sep 1, 2016

👍

@krupalshah

This comment has been minimized.

Copy link

commented Sep 1, 2016

I showed it to my boss and he now wants PHava in production. He believes in cheap and fast. :P

@john-w-k

This comment has been minimized.

Copy link

commented Sep 1, 2016

I'm going to create an IDE for this called "Chianti"

@alrz

This comment has been minimized.

Copy link

commented Sep 1, 2016

I don't know what is that function in Java ..

@IllusionMH

This comment has been minimized.

Copy link

commented Sep 1, 2016

@cpmiller but why not PHava Jeans?

@brunoleles

This comment has been minimized.

Copy link

commented Sep 1, 2016

@mendelgusmao

This comment has been minimized.

Copy link

commented Sep 1, 2016

Phava +1

It reminds me a bit of the portuguese expression "vá às favas", which grossly translates to "gtfo"

lol

@krhancoc

This comment has been minimized.

Copy link

commented Sep 1, 2016

Don't let you're Phava dreams be dreams guys.

@clod81

This comment has been minimized.

Copy link

commented Sep 1, 2016

a3ac1c00f83229732d780f09464fe58cdd9e93f4_m

@vyscond

This comment has been minimized.

Copy link

commented Sep 2, 2016

its_a_no_for_me

@NotMrPink

This comment has been minimized.

Copy link

commented Sep 2, 2016

You were so preoccupied with whether or not you could, you didn't stop to think if you should.
+1

Phava
+1

@hbthegreat

This comment has been minimized.

Copy link

commented Sep 2, 2016

Why is Phava phaping?

@matejjelic

This comment has been minimized.

Copy link

commented Sep 2, 2016

But... will it blend?

@RSickenberg

This comment has been minimized.

Copy link

commented Sep 2, 2016

Just here to read the comments

@Marti2203

This comment has been minimized.

Copy link

commented Sep 2, 2016

Can somebody explain what happens after the printf, a string is printed and after that I haven't got a clue what is going on except that a class is created.

@jmcclell

This comment has been minimized.

Copy link

commented Sep 2, 2016

Sure, but does it transpile to Javascript?

@castroalves

This comment has been minimized.

Copy link

commented Sep 2, 2016

Why not Japha?

@saturnaut

This comment has been minimized.

Copy link

commented Sep 2, 2016

juba

@JesterXL

This comment has been minimized.

Copy link

commented Sep 2, 2016

Am I the only one who thought about the current USA election when seeing both code snippets?

@Viperoo

This comment has been minimized.

Copy link

commented Sep 3, 2016

PHava+1

gif

@shubanker

This comment has been minimized.

Copy link

commented Sep 4, 2016

I once had a similar idea of PHP in java and created this

@Ishtiaque-Shaad

This comment has been minimized.

Copy link

commented Sep 4, 2016

Yoo Bro!

@ndugger

This comment has been minimized.

Copy link

commented Sep 6, 2016

This is disgusting, and you should be ashamed. Both languages are already gross; mashing them together just makes me sick.

@index0h

This comment has been minimized.

Copy link

commented Sep 11, 2016

+1 bravo!

@imachug

This comment has been minimized.

Copy link

commented Sep 12, 2016

+1 for Phava!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.