jphp icon indicating copy to clipboard operation
jphp copied to clipboard

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

Open rioastamal opened this issue 5 years ago • 1 comments

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

rioastamal avatar Nov 02 '20 03:11 rioastamal

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

AlLiberali avatar Mar 22 '21 07:03 AlLiberali