From: <php...@li...> - 2015-09-20 18:41:23
|
I have not messed around much with the bridge under tomcat, or with calling php from java, however as soon as you wrap the thing into a java object, java rules obtain, so I would agree that the perhaps teste needs to be declared public, and probably it should return a valid java type (like String)? The FAQ includes an example: This relies on the toString method that is inherited by ANY java object and is inherited as public. So as above, may try declring the function as public, and proably get it to return a |java("java.lang.String") object instead of a simple php string. | How can I convert a PHP object into a Java object? With |java_closure()|. For example: | class Foo { function toString() {return "php::foo";} } $foo = new Foo(); $jObj = java_closure($foo); $String = java("java.lang.String"); echo $String->valueOf($jObj);| php...@li... wrote: > Hello Numa, > thanks for answer. This is not a Java class. It is a PHP class that I want to "convert" to Java class via java_closure, because in the real program it will be used by other "native" Java classes (passed as parameter). > Ely Matos > > -----Original Message----- > From: php...@li... [mailto:php...@li...] > Sent: terça-feira, 15 de setembro de 2015 09:48 > To: php...@li... > Subject: Re: [Php-java-bridge-users] Simple closure not working - correction > > Hi, > > I can’t see how your java class can work or even compile, as it does not look syntactically correct, it should be: > public class TesteClass > { > > public String teste() > { > return 'teste'; > } > > } > > Rgds, > Numa > > > >> Le 15 sept. 2015 à 14:16, php...@li... a écrit : >> >> Sorry, of course I put >> require_once("java/Java.inc"); >> on code... >> TIA >> Ely Matos >> >> -----Original Message----- >> Hello, >> I know this is a stupid question, but I actually tried almost everything >> (docs, google, mailing list, etc.). I don't know why this simple closure is >> not working. I'm sure there is an obvious reason, but I'm not seeing. >> TIA, >> Ely Matos >> >> >> <?php >> try { >> /* create a Java object from the PHP object */ >> $javaObject = java_closure(new TesteClass()); >> echo "PHP says that Java says: "; >> echo $javaObject->teste(); >> echo "<br>\n"; >> echo "<br>\n"; >> >> } catch (JavaException $ex) { >> echo "An exception occured: "; >> echo $ex; >> echo "<br>\n"; >> } >> >> class TesteClass >> { >> >> function teste() >> { >> return 'teste'; >> } >> >> } >> ?> >> >> On execution, I receive: >> >> PHP says that Java says: An exception occured: >> [[o:Exception]:"java.lang.Exception: Invoke failed: [[o:$Proxy37]]->teste. >> Cause: java.lang.NoSuchMethodException: teste(). Candidates: [] VM: >> 1.7.0_25@http://java.oracle.com/" at: >> #-6 php.java.bridge.JavaBridge.checkM(JavaBridge.java:1085) >> #-5 php.java.bridge.JavaBridge.Invoke(JavaBridge.java:1024) >> #-4 php.java.bridge.Request.handleRequest(Request.java:417) >> #-3 php.java.bridge.Request.handleRequests(Request.java:500) >> #-2 php.java.bridge.http.ContextRunner.run(ContextRunner.java:145) >> #-1 php.java.bridge.ThreadPool$Delegate.run(ThreadPool.java:60) >> #0 C:\Program Files\Apache Software >> Foundation\apache-tomcat-7.0.62\webapps\mknob\java\Java.inc(232): >> java_ThrowExceptionProxyFactory->getProxy(2, 'com.sun.proxy.$...', 'T', >> true) >> #1 C:\Program Files\Apache Software >> Foundation\apache-tomcat-7.0.62\webapps\mknob\java\Java.inc(360): >> java_Arg->getResult(true) >> #2 C:\Program Files\Apache Software >> Foundation\apache-tomcat-7.0.62\webapps\mknob\java\Java.inc(366): >> java_Client->getWrappedResult(true) >> #3 C:\Program Files\Apache Software >> Foundation\apache-tomcat-7.0.62\webapps\mknob\java\Java.inc(560): >> java_Client->getResult() >> #4 C:\Program Files\Apache Software >> Foundation\apache-tomcat-7.0.62\webapps\mknob\java\Java.inc(1752): >> java_Client->invokeMethod(1, 'teste', Array) >> #5 C:\Program Files\Apache Software >> Foundation\apache-tomcat-7.0.62\webapps\mknob\java\Java.inc(1851): >> java_JavaProxy->__call('teste', Array) >> #6 C:\Program Files\Apache Software >> Foundation\apache-tomcat-7.0.62\webapps\mknob\java\Java.inc(1999): >> java_AbstractJava->__call('teste', Array) >> #7 C:\Program Files\Apache Software >> Foundation\apache-tomcat-7.0.62\webapps\mknob\closure.php(8): >> Java->__call('teste', Array) >> #8 C:\Program Files\Apache Software >> Foundation\apache-tomcat-7.0.62\webapps\mknob\closure.php(8): >> java_InternalJava->teste() >> #9 {main}]<br> >> >> >> ---------------------------------------------------------------------------- >> -- >> _______________________________________________ >> php-java-bridge-users mailing list >> php...@li... >> https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users >> >> >> ------------------------------------------------------------------------------ >> _______________________________________________ >> php-java-bridge-users mailing list >> php...@li... >> https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users >> > > > ------------------------------------------------------------------------------ > _______________________________________________ > php-java-bridge-users mailing list > php...@li... > https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users > > > ------------------------------------------------------------------------------ > _______________________________________________ > php-java-bridge-users mailing list > php...@li... > https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users > |