From: <php...@li...> - 2011-01-17 18:09:05
|
Hi there, A couple of quick questions with regards to coding techniques using PHP, the JavaBridge and third-party classes...I have tried to keep my examples brief, generic and concise! 1) When using Java, an example line of code could be "ExampleClass.TestSomething().Item(this);" which when translated into PHP would be the same as "ExampleClass->TestSomething()->Item(???);" but what should I be using for the Java keyword "this" in PHP script? Obviously the PHP equivalent "$this" is not right for this requirement when needing to refer to the current Java object's context. 2) Is it possible to create user defined callback interfaces to Java in PHP script when using the JavaBridge? Using third-party classes, I'm successfully instantiating a class called "Problem" which has a method called "Optimise". This all runs fine, in effect in a black box, and comes back with a successful result. However, as part of the processing this class does when Optimise is invoked is to call a public Java interface called "IEvaluator" after each iteration of calculations being done under the covers. In Java, IEvaluator has one method called "Evaluate" and is referred to as a user defined callback interface. Now if I wanted to hook into this interface to get results after each iteration and was coding this in Java, I would simply ensure my own class implements IEvaluator and create a public class implementing "Evaluate", which would then get called after each round of calculations. E.g.: public class Example1 implements IEvaluator { public int Evaluate(Evaluator evaluator) { Do something here like print iteration number to the screen; return something like a carry on processing flag; } ...more Java code where Problem.Optimise() is invoked etc; } But how would I in PHP provide the same user defined interface for the same Java class to use? I have looked at loads of examples but they do not seem to point me in the right direction. Is this possible? Thanks in advance for any help. Cheers, Marc The information contained in this E-mail is confidential. It is intended only for the stated addressee(s) and access to it by any other person is unauthorised. If you are not an addressee, you must not disclose, copy, circulate or in any other way use or rely on the information contained in this E-mail. Such unauthorised use may be unlawful. If you have received this E-mail in error, please inform us immediately and delete it and all copies from your system. |