Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7660295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:26:48+00:00 2026-05-31T13:26:48+00:00

I have some code similar to this: QuercusEngine engine = new QuercusEngine(); Value value

  • 0

I have some code similar to this:

QuercusEngine engine = new QuercusEngine();
Value value = engine.execute("<?php return $obj->getName(); ?>");
System.out.println(value);

(See http://wiki.caucho.com/Quercus:_Command_Line_Interface_(CLI) for more info)

I want to set $obj as a java instance. Something like this:

SomeObject someObject = new SomeObject();
engine.setParam("obj", someObject);

Obviously this is a simplistic example but the point is that I want to be able to use instances of java classes that have already been instantiated in the php script. How could I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:26:48+00:00Added an answer on May 31, 2026 at 1:26 pm

    I don’t think this is documented anywhere, but after looking through the source code, looking at what the QuercusEngine was doing, and a little trial and error this is what it takes:

    Path path = new StringPath("<?php return $obj->getName(); ?>");
    QuercusContext quercusContext = new QuercusContext();
    ReadStream reader = path.openRead();
    QuercusProgram program = QuercusParser.parse(quercusContext, null, reader);
    WriteStream out = new WriteStream(StdoutStream.create());
    QuercusPage page = new InterpretedPage(program);
    
    Env env = new Env(quercusContext, page, out, null, null);
    
    SomeObject someObj = new SomeObject();
    
    JavaClassDef classDef = env.getJavaClassDefinition(someObject.getClass());
    env.setGlobalValue("obj", new JavaValue(env, someObject, classDef));
    
    Value value = NullValue.NULL;
    
    try {
      value = program.execute(env);
    }
    catch (QuercusExitException e) {
    }
    
    out.flushBuffer();
    out.free();
    
    System.out.println(value);
    

    Hope this helps someone. I tested this in Quercus 4.0.25.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a windows service written around some code similar to this Asynchronous Server
I've have some code similar to this: HttpWebRequest req; HttpWebResponse response; Stream receiveStream =
I have some code similar to the following: public interface IMyClass { MyEnum Value
I have some java code that looks similar to this: private void startServer() throws
I have some code with the a structure similar to this function bbcode($Text) {
I have a some simple Java code that looks similar to this in its
I have some jQuery code similar to this: var refreshStuff = setInterval(function() { $.ajax({
I have some code like this in a winforms app I was writing to
I have some code like this: If key.Equals(search, StringComparison.OrdinalIgnoreCase) Then DoSomething() End If I
In a PHP project I am working on right now, I have some code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.