# Function java_call_with_continuation

Call the current Java continuation with the closed-over PHP environment $kontinuation as its argument.

This procedure can be used to transfer control back to a Java continuation so that Java can call PHP procedures defined within the passed environment. If no current Java continuation exists, the procedure does nothing.

Example PHP script:

    <?php require_once("java/Java.inc");

    // ... calculate sales for a given month ...
    function calculateSales($month) {return ((int)(string)$month)+1;}

    write_response($response);

    // prepare for out-of-band data: make our top-level environment
    // available to Java. But only if it has been requested by Java:
    java_call_with_continuation();
    ?>

If the above PHP script is named "calculateSales.php", the JSR 223 API can be used to invoke its functions or methods, to debug or test certain functionality from Java while keeping the script running in a production environment. The Java code follows:

    import javax.script.*;
    import java.net.*;
    import java.io.*;
    class SalesTest {
        public static void test(Integer month) throws Exception {
            ScriptEngine e = new ScriptEngineManager().getEngineByName("php-invocable");
         ByteArrayOutputStream out;
         OutputStreamWriter writer;
         e.getContext().setWriter(writer=new OutputStreamWriter(out=new ByteArrayOutputStream()));
            Object res=e.eval(new php.java.script.URLReader(new URL("http://localhost/calculateSales.php")));
            System.err.println(((Invocable)e).invokeFunction("calculateSales", new Object[]{month}));
            ((Closeable)e).close();
            System.err.println("PHP exit() code:" + String.valueOf(res));
            System.err.println("PHP output:" + String.valueOf(out));
         }
         public static void main(String s[]) throws Exception {
            test(new Integer(12));
         }
    }

The above Java program opens a URL connection to the PHP script, invokes the calculateSales() function from the passed PHP environment and then outputs the exit code and the HTML response of the PHP script.

License: GPL
Author: Jost Boekemeier
Located at JavaBridge.inc

Parameters summary
`mixed` | `$kontinuation = null` | either be null, a PHP function name, a PHP object or a java_closure. If a PHP object is provided, the object is passed to Java. If a function name is provided, the function must return a java_closure. Otherwise the current environment is used.