PHP/Java Bridge - Access Java objects in PHP

Posted by Omer Hassan on Stack Overflow See other posts from Stack Overflow or by Omer Hassan
Published on 2012-10-08T13:45:35Z Indexed on 2012/10/08 15:38 UTC
Read the original article Hit count: 355

Filed under:
|
|

I have a Red5 application which defines some public Java methods. When I start the server, an object of the application class gets created. I am trying to call the public methods of the application class from PHP using the existing instance of the Java application class.

So here's my Java application:

public class App extends org.red5.server.adapter.ApplicationAdapter
{
    public boolean appStart(IScope app)
    {
        // This method gets called when the application starts
        // and an object of this App class is created.
        return true;
    }

    // This is the method I would like to call from PHP.
    public void f()
    {
    }
}

From PHP, I would like to get access to the App object that is created and call the method f() on it.

I have tried playing around with this thing called "context". So in the Java method App.appStart(), I did this:

// Save a reference to this App object to be retrieved later in PHP.
new PhpScriptContextFactory().getContext().put("x", this);

And in PHP, I tried to access the saved object like this:

require_once("http://localhost:5080/JavaBridge/java/Java.inc");
var_dump(java_is_null(java_context()->get("x")));

Unfortunately, the java_is_null() function in PHP returns true.

I also tried saving the App object in a static variable of App class but when I access that variable in PHP, its value is null.

© Stack Overflow or respective owner

Related posts about java

Related posts about php