![]() |
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Resin 3.1 Documentation Examples Changes Overview Installation Configuration Quercus SOA/IoC JSP Servlets and Filters Admin (JMX) EJB Amber Security Performance Hessian XML and XSLT Third-party Troubleshooting/FAQ Getting Started Overview Security Module Status Resin Module Java Interface List of PHP Applications |
Quercus types, Java-Quercus type mappings, working with Java Classes in PHP IntroductionIntegrating PHP and Java Quercus TypesFor every PHP type, there is a Quercus type that is used
internally to represent the corresponding PHP value. All Quercus types extend
Quercus natively supports Unicode and is compatible with the new PHP 6 syntax. Java Method ArgumentsIn Quercus, Java methods can be called from within PHP. Java arguments for Java methods need to be marshaled to the correct type from the PHP parameters that were passed in.
When the Java argument type is declared to be Object, the value will be marshaled to a Java object. For example, a PHP int (LongValue) will be marshaled to an Integer. The only exceptions are PHP arrays and objects: they are passed in as-is without marshaling. When the Java argument type is declared to be a Quercus Value, the PHP value is passed in directly without marshaling. If the Java argument type is an object, passing in a PHP Java Method ReturnsWhen a Java method is called from PHP code, the return value of that Java method needs to be marshaled into a valid Quercus value.
Java objects like Calendar and Map are placed inside JavaValues and then
returned to the PHP environment. A JavaValue is just a wrapper that exposes
the object's Java methods to PHP. For example, if Some Java objects may have an effective PHP value. Take for instance, Date. A Date object is, for practical purposes, a PHP int with it's value pegged to Date.getTime(). Collection, List, and Map behave just like PHP arrays. Suppose
Working with Java Classes in PHPInstantiating ObjectsTo get new instances of Java ojects, use
<?php
$a = new java("java.util.Date", 123);
echo $a->nanoTime();
?>
Accessing static members and functionsTo get the class of the Java object without calling the constructor, use
<?php
$class = java_class("java.lang.System");
// System.in
$in = $class->in;
// System.currentTimeInMillis();
$time = $class->currentTimeInMillis();
?>
Special Quercus Keywordsimport Keyword in PHPQuercus supports the
<?php
import java.util.Vector;
import java.util.Date;
$vector = new java("Vector");
$date = new Date(123);
?>
The Java Method OverloadingQuercus allows overloaded Java methods to be called from within PHP code. Quercus will try to use the method whose arguments are the most easily marshaled (i.e. a PHP string easily goes into a Java String whereas a PHP array is a mismatch for a Java int).
import com.caucho.quercus.module.AbstractQuercusModule;
public class MyModule extends AbstractQuercusModule
{
public static void foo(String a, boolean b)
{
}
public static void foo(String a, String b)
{
}
}
<?php
foo('abc', false);
?>
In the example above, the first Java method
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||