Hi,
I am attempting to call PHP from a JAVA application where the invocation
returns a PHP object. The result is that there is no response coming across
from the bridge, and the JAVA application seems to just continue aimlessly.
My JAVA code is:
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine e = manager.getEngineByName("php-invocable");
java.io.File sourceFile = new java.io.File("c:/test.php");
java.io.FileReader fr = new java.io.FileReader(sourceFile);
e.eval(fr);
Invocable i = (Invocable) e;
try {
String t = (String) i.invokeFunction("f", new Object[] {});
System.out.println("test 1 okay || " + t);
} catch (Throwable ex) {
ex.printStackTrace();
System.exit(2);
}
The PHP code (just a simple example) called is in a text file and is as
follows:
<?php
function f(){
$t=new c();
return $t;
}
class c{
function p(){
return 'p ok';
}
}
?>
Is it possible to make a call from JAVA like this over the bridge that gets
back the PHP object 't' of class 'c' (more in general, to have a
non-standard PHP object returned to JAVA)? If so, how? And also, of what
form is the object that is returned? In the end I would like to get back an
object of class 'c', so I can call its function 'p' as a normal JAVA method.
Pls note by the way that calling the php code directly in an eval statement
in the JAVA application leads to the same issue.
I am aware that I can simply register a new object of class c in the php by
including:
java_context()->setAttribute('c', java_closure(new c()), 100);
and then call the function 'p' via the invokeMethod method in JAVA.
However, I was wondering whether it is possible to get back objects without
having to alter the PHP code.
Thanks for any insight.
Bart Orriens
|