|
|
|
An amazing functionality of PHP is its ability to invoke methods of existing Java objects, letting you integrate PHP into existing Java-based applications.
To employ this functionality, you need to have a Java Virtual Machine (JVM) installed on the server. If you have installed JDKs from Sun, IBM, or Black down, you will be up to the speed.
When you configure PHP, add --with-java to the configuration directives, and then change some elements of the php.ini file. The php.ini modifications are usually done by adding the following the lines:
[Java]
java.library.path=/path/to/library
java.class.path=/classpath/
extension_dir=/path/to/extensions
extension=libphp_java.so
However, that these modifications completely depend on the type of installation. Go through the README in the ext/java directory in the PHP installation directory to discover more about configuring for Java functionality.
Here is a very simple illustration of a PHP script creating a new Java object. The script will then access and print to the screen few Java properties.
<?
$system = new Java("java.lang.System");
echo "<P>Java version = " . $system->getProperty("java.version") . "<br>";
echo "Java vendor = " . $system->getProperty("java.vendor") . "</p>";
?>
These types of integration capability will be key in the future acceptance and growth of PHP, enabling more people to work on it. |
|