Skip to content
memory-agape edited this page Apr 18, 2019 · 4 revisions

PHPJava\Kernel\Types\_Byte

Introduction

_Byte class is provided APIs for emulating Java's byte on PHPJava. This class not been determined of features.

How to use

The class can be pass byte type into Java if you want. For an example as follows:

  1. Write Java:
class Test 
{
    public static void echo(byte[] text)
    {
        System.out.println(new String(text));
    }
}
  1. Compile Java:
$ javac -UTF8 /path/to/Test.java
  1. Call the echo method as follows:
<?php
use PHPJava\Core\JavaClass;
use PHPJava\Core\Stream\Reader\FileReader;
use PHPJava\Kernel\Types\\_Byte;

(new JavaClass(new FileReader('/path/to/Test.class')))
    ->getInvoker()
    ->getStatic()
    ->getMethods()
    ->call(
        'echo',
        array_map(
            function ($char) {
                return new _Byte(ord($char));                
            },
            preg_split(
                '//',
                 "HelloWorld!", 
                 -1, 
                 PREG_SPLIT_NO_EMPTY
            )
        )
    );
  1. Get the result
$ php /path/to/Test.php
HelloWorld!

Provided methods

Name

public function __construct($value)
Introduction

Initiate a boolean type for Java.

Parameters
Name Type Description
$value mixed Specify byte value

Name

public function getValue()
Introduction

Return real value.

Parameters

No parameter.

Name

public function getTypeNameInJava()
Introduction

Return type name in Java.

Parameters

No parameter.

Name

public function getTypeNameInPHP()
Introduction

Return type name in PHP.

Parameters

No parameter.

Name

public function __toString()
Introduction

Return stringified real value.

Parameters

No parameter.

Clone this wiki locally