From: <php...@li...> - 2006-11-17 15:54:16
|
Sorry, once again ;-) I wrote this little part of a Java method for testing: PhpScriptEngine engine = new PhpScriptEngine(); String s = "<?php \n"; s += "require_once 'MyClass.php'; \n"; s += "java_context()->setAttribute( 'obj', new MyClass(), 100 ); \n"; s += "java_context()->call(java_closure()); \n"; s += "?>"; engine.eval( new StringReader(s) ); Invocable inv = (Invocable) engine; inv.invokeMethod( engine.get("obj"), "saySomething", new Object() ); The resulting errors are: java.lang.NullPointerException at java.lang.reflect.Proxy.getInvocationHandler(Proxy.java:636) at php.java.script.PhpScriptEngine.invokeMethod(PhpScriptEngine.java:202) at Bootstrap.main(Bootstrap.java:30) Nov 17 16:30:28 JavaBridge ERROR: PHP Warning: Argument is not (or does not contain) Java object(s). in - on line 3 The NullPointerException happens in the line where invokeMethod is called. Line 3 of the PHP script is the one where setAttribute() is called. As I understand the error message text, it is not possible to set a PHP object as an attribute to the java context, but only Java objects? Another thing I tried was: String s = "<?php \n"; s += "require_once 'MyClass.php'; \n"; s += "$obj = new MyClass(); \n"; s += "java_context()->call(java_closure()); \n"; s += "?>"; but there was the same NullPointerException. This was inspired from the Javascript example provided by SUN here: https://java.sun.com/javase/6/docs/technotes/guides/scripting/programmer_guide/index.html#invoke ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("JavaScript"); String script = "var obj = new Object(); obj.hello = function(name) { print('Hello, ' + name); }"; engine.eval(script); Invocable inv = (Invocable) engine; Object obj = engine.get("obj"); inv.invokeMethod(obj, "hello", "Script Method !!" ); Any chance todo something similar with PHP? Regards, Verena |