Access the java type with the given name.
Access the java type with the given name.
This procedure can be used to access constants or procedures within a class.
To access class features, use the java constructor instead.
Example:
java("java.lang.Long")->MAX_VALUE
Any declared exception can be caught by PHP code.
Exceptions derived from java.lang.RuntimeException or Error must not be caught unless declared in the methods throws clause -- OutOfMemoryErrors cannot be caught at all, even if declared.
void
Java
(string $name)
-
string
$name: The type name
java_call_with_continuation (line
375)
Call the Java continuation with the closed-over PHP environment $kontinuation as its argument.
Call the Java continuation with the closed-over PHP environment $kontinuation as its argument.
This procedure can be used to transfer control back to a Java continuation so that Java can call PHP procedures defined within the passed environment. If the script has not been requested by Java, the procedure does nothing.
Example PHP script:
<?php require_once("java/Java.inc");
class my_SalesCalculator { function calculateSales($month) {return ((int)(string)$month)+1;} ... }
// ... calculate sales for a given month ...
write_response($response);
// prepare for out-of-band data: make our top-level environment
// available to Java. But only if it has been requested by Java:
?>
If the above PHP script is named "calculateSales.php", the JSR 223 API can be used to invoke its functions or methods, to debug or test certain functionality from Java while keeping the script running in a production environment. The Java code follows:
import javax.script.*;
import java.net.*;
import java.io.*;
class SalesTest {
public static void test(Integer month) throws Exception {
ScriptEngine e = new ScriptEngineManager().getEngineByName("php-invocable");
ByteArrayOutputStream out;
OutputStreamWriter writer;
e.getContext().setWriter(writer=new OutputStreamWriter(out=new ByteArrayOutputStream()));
Object res=e.eval(new php.java.script.URLReader(new URL("http://localhost/calculateSales.php")));
System.err.println(((Invocable)e).invokeFunction("calculateSales", new Object[]{month}));
((Closeable)e).close();
System.err.println("PHP exit() code:" + String.valueOf(res));
System.err.println("PHP output:" + String.valueOf(out));
}
public static void main(String s[]) throws Exception {
test(new Integer(12));
}
}
The above Java program opens a URL connection to the PHP script, invokes the calculateSales() function from the passed PHP environment and then outputs the exit code and the HTML response of the PHP script.
void
java_call_with_continuation
([mixed $kontinuation = null])
-
mixed
$kontinuation: If a PHP object is provided, the object is passed to Java. Otherwise the current environment is used.
Checks whether a value is false or not.
Checks whether a value is false or not.
Example:
true
java_is_false
(mixed $value)
-
mixed
$value: A Java object or a PHP value
Checks whether a value is null or not.
Checks whether a value is null or not.
Example:
true
java_is_null
(mixed $value)
-
mixed
$value: A Java object or a PHP value
Checks whether a value is true or not.
Checks whether a value is true or not.
Example:
true
java_is_true
(mixed $value)
-
mixed
$value: A Java object or a PHP value