PDA

View Full Version : 'ini_get' is an unknown function


magiconair
03-17-2011, 06:51 PM
Hi,

I am trying to integrate Quercus 4.0.11 into a standalone application and I am getting a strange error in a very simple app which I think should just work.

I've checked out the source code for the 4.0.11 tag from SVN, ran "ant" to build the JAR files. Then I've created a simple project which inclucdes quercus.jar, resin-kernel.jar and servlet-16.jar. The class looks like this:


import com.caucho.quercus.QuercusEngine;
import com.caucho.quercus.env.Value;
import java.io.IOException;

public class QuercusTest {
public static void main(String[] args) throws IOException {
QuercusEngine engine = new QuercusEngine();
engine.setIni("foo", "bar");
Value value = engine.execute("<?php return ini_get('foo'); ?>");
System.out.println(value);
}
}


When I try to run this code I can see that the OptionsModule was found and I've also confirmed that it is in the JAR.


INFO: CLAXX: class com.caucho.quercus.lib.OptionsModule
Mar 17, 2011 7:33:50 PM com.caucho.quercus.module.ModuleContext introspectPhpModuleClass


However, I get the following error.


Exception in thread "main" com.caucho.quercus.QuercusErrorException: eval::1: Fatal Error: 'ini_get' is an unknown function.
at com.caucho.quercus.env.Env.error(Env.java:6469)
at com.caucho.quercus.env.Env.error(Env.java:6355)
at com.caucho.quercus.env.Env.error(Env.java:6019)
at com.caucho.quercus.expr.CallExpr.evalImpl(CallExpr .java:198)
at com.caucho.quercus.expr.CallExpr.eval(CallExpr.jav a:151)
at com.caucho.quercus.expr.Expr.evalValue(Expr.java:4 69)
at com.caucho.quercus.statement.ReturnStatement.execu te(ReturnStatement.java:69)
at com.caucho.quercus.program.QuercusProgram.execute( QuercusProgram.java:412)
at com.caucho.quercus.QuercusEngine.execute(QuercusEn gine.java:139)
at com.caucho.quercus.QuercusEngine.execute(QuercusEn gine.java:100)
at QuercusTest.main(QuercusTest.java:16)


Since the example is so simple and also taken almost literally from the Wiki I think I'm missing something obvious here.

Any help or insight is highly appreciated.

Thanks
Frank

domdorn
03-17-2011, 11:16 PM
you're not initializing quercus correctly.

take a look at modules/quercus/src/com/caucho/quercus/Quercus.java#main and other functions to see how it should work.

magiconair
03-17-2011, 11:27 PM
I thought that there must be a different approach. I will try that tomorrow.

However, this wiki page describes the approach I've taken for 4.0.2+

http://wiki.caucho.com/Quercus:_Command_Line_Interface_%28CLI%29

Is the page incomplete or has something changed in the meantime?

Thanks for the quick reply
Frank

magiconair
03-18-2011, 12:50 AM
By adding the call getQuercus().init() the example works. Since QuercusEngine is just a thin wrapper around QuercusContext I wonder why _quercus.init() isn't called when the QuercusEngine object is created.

This works now

import com.caucho.quercus.QuercusEngine;
import com.caucho.quercus.env.Value;

import java.io.IOException;

public class QuercusTest {
public static void main(String[] args) throws IOException {
QuercusEngine engine = new QuercusEngine();
engine.getQuercus().init();
engine.getQuercus().start();
engine.setIni("foo", "bar");
Value value = engine.execute("<?php return ini_get('foo'); ?>");
System.out.println(value);
}
}