jphp-group / jphp

JPHP - an implementation of PHP on Java VM
http://jphp.develnext.org
Apache License 2.0
1.71k stars 161 forks source link

How to call Java Standard Libraries in JPHP Like in PeachPie (.NET)? #417

Open rioastamal opened 3 years ago

rioastamal commented 3 years ago

I can do this in PeachPie (PHP Compiler for .NET) which is basically calling .NET standard libraries.

<?php
use \System\Console;
use \System\IO\StreamReader;
use \System\Net\WebRequest;

function main()
{
    $uri = $_SERVER['argv'][1];

    $http = WebRequest::Create($uri);
    $response = $http->GetResponse();
    $stream = new StreamReader( $response->GetResponseStream() );

    Console::WriteLine( "HTTP Response:\n" . $stream->ReadToEnd() );
}

main();

How to do call Java standard libraries like the one above? I've tried this one.

<?php

function main() {
    \System\out::println("Hello World\n");
}

main();

But it gives me.

$ jppm start
-> linux
-> app:run
-> install

Fatal error: Uncaught Error: Class 'System\out' not found in res://index.php on line 4, position 12
Stack Trace:
#0 <internal>() called at [res://index.php:1]
#1 main() called at [res://index.php:7]
#2 {main}
  thrown in res://index.php on line 4
AlLiberali commented 3 years ago

Maybe because in Java out is a field of System and you should access it like a field. Console is a class of System package in .net