java_begin_document (line
490)
Enters stream mode (asynchronuous protocol).
Enters stream mode (asynchronuous protocol).
The statements are sent to the back-end in one XML stream.
Use this protocol mode when you have a large number of set operations and you don't expect an exception. Any exception raised during stream mode is reported when java_end_document() is called.
void
java_begin_document
()
Converts the java object obj into a PHP value.
Converts the java object obj into a PHP value.
This procedure converts the Java argument and then calls java_values() to fetch its content. Use java_values() if the conversion is not necessary.
The second argument must be [s]tring, [b]oolean, [i]nteger, [f]loat or [d]ouble, [a]rray, [n]ull or [o]bject (which does nothing).
Example:
$str = new java("java.lang.String", "12");
=> #f
$phpString = (string)$str;
=> #t
$phpNumber = (integer)(string)$str;
echo $phpNumber;
=> 12
echo $phpNumber2;
=> 12
void
java_cast
(object A $object, string $type)
-
object A
$object: java object
-
string
$type: A PHP type description, either [Ss]tring, [Bb]oolean, [Ll]ong or [Ii]nteger, [Dd]ouble or [Ff]loat, [Nn]ull, [Aa]rray, [Oo]bject.
Wraps a PHP environment.
Wraps a PHP environment.
Closes over the php environment and packages it up as a java class. Use java_closure() to convert a PHP object into an equivalent Java object.
Example:
function toString() {return "helloWorld";};
echo "Java says that PHP says: $object\n";
When a php instance is supplied as an argument, the instance will be used instead. When a string or key/value map is supplied as a second argument, the java procedure names are mapped to the php procedure names. Example:
function hello() {return "hello";};
When an array of java interfaces is supplied as a third argument, the environment must implement these interfaces. Example:
class Listener {
function actionPerformed($actionEvent) {
...
}
}
function getListener() {
return java_closure(new Listener(), null, array(new Java("java.awt.event.ActionListener")));
}
void
java_closure
()
Returns the jsr223 script context handle.
Returns the jsr223 script context handle.
Example which closes over the current environment and passes it back to java:
A second example which shows how to invoke PHP methods without the JSR 223 getInterface() and invokeMethod() helper procedures:
String s = "<?php class Runnable { function run() {...} };
// example which captures an environment and
// passes it as a continuation back to Java
$Runnable = java('java.lang.Runnable');
java_context()->setAttribute("kont", $closure, ENGINE_SCOPE);
?>";
ScriptEngine e = new ScriptEngineManager().getEngineByName("php-invocable");
e.eval (s);
Runnable r = e.get("kont");
new Thread(r).start();
It is possible to access implicit web objects (the session, the application store etc.) from the context. Please see the JSR223 documentation for details. Example:
$req = $ctx->getHttpServletRequest();
$res = $ctx->getHttpServletResponse();
Example which fetches the servlet-, config and context:
$config = $ctx->getAttribute ( "php.java.servlet.ServletConfig", ENGINE_SCOPE);
$context = $ctx->getAttribute( "php.java.servlet.ServletContext", ENGINE_SCOPE);
$servlet = $ctx->getAttribute( "php.java.servlet.Servlet", ENGINE_SCOPE);
void
java_context
()
java_end_document (line
505)
Ends stream mode.
Ends stream mode.
Fires a JavaException if any statement executed during stream mode raised an exception.
void
java_end_document
()
Returns the contents (public fields, public methods, public classes) of object as a string.
Returns the contents (public fields, public methods, public classes) of object as a string.
Example:
void
java_inspect
(object A $object)
-
object A
$object: java object or type.
java_instanceof (line
192)
Tests if object is an instance of clazz.
Tests if object is an instance of clazz.
Example:
void
java_instanceof
(object A $ob, object A $clazz)
-
object A
$ob: java object
-
object A
$clazz: java object or type.
Set the library path.
Set the library path.
Example:
The .jar files should be stored in /usr/share/java or extension_dir/lib one of its sub-directories or under the PHP include_path/LIBNAME/LIBNAME.jar. However, it is also possible to fetch .jar files from a remote server, for example:
Note that Java doesn't have a module system. Therefore libraries and their dependencies must be loaded by one and only one class loader; do not report a ClassCastException saying that a class is incompatible to itself or a NoClassDefFoundError to the PHP/Java Bridge mailing list.
void
java_require
(string $arg)
-
string
$arg: The list of Java libraries.
Only for internal use.
Only for internal use.
void
java_reset
()
java_server_name (line
355)
Returns the name of the back-end or null, if the back-end is not running.
Returns the name of the back-end or null, if the back-end is not running.O
Example:
if(!$backend) wakeup_administrator("back-end not running");
echo "Connected to the back-end: $backend\n";
void
java_server_name
()
Return a session handle.
Return a session handle.
When java_session() is called without arguments, the session is shared with java. Example:
The java components (jsp, servlets) can retrieve the value, for example with:
getSession().getAttribute("key");
When java_session() is called with a session name, the session is not shared with java and no cookies are set. Example:
java_session("myPublicApplicationStore")->put("key", "value");
When java_session() is called with a second argument set to true, a new session is allocated, the old session is destroyed if necessary. Example:
The optional third argument specifies the default lifetime of the session, it defaults to
. The value 0 means that the session never times out.
void
java_session
()
java_set_file_encoding (line
167)
Set the java file encoding, for example UTF-8 or ASCII.
Set the java file encoding, for example UTF-8 or ASCII.
Needed because php does not support unicode. All string to byte array conversions use this encoding. Example:
void
java_set_file_encoding
(string $enc)
-
string
$enc: A valid file.encoding string. Please see your Java documentation for a list of valid encodings.
Unwraps a Java object.
Unwraps a Java object.
Evaluates the object and fetches its content, if possible. Use java_values() to convert a Java object into an equivalent PHP value.
A java array, Map or Collection object is returned as a php array. An array, Map or Collection proxy is returned as a java array, Map or Collection object, and a null proxy is returned as null. All values of java types for which a primitive php type exists are returned as php values. Everything else is returned unevaluated. Please make sure that the values do not not exceed php's memory limit. Example:
$str = new java("java.lang.String", "hello");
=> hello
$chr = $str->toCharArray();
echo $chr;
=> [o(array_of-C):"[C@1b10d42"]
print $ar;
=> Array
print $ar[0];
=> [o(Character):"h"]
=> h
void
java_values
(object A $object)
-
object A
$object: java object or type.