PHP and Java
Another great feature of PHP is its ability to call methods of existing Java objects. This feature allows you to integrate PHP into existing Java-based applications. If you're promoting PHP in your workplace, you've got something to brag about because Java is everywhere.
In order to use this feature, you need to install a Java Virtual Machine (JVM) on the server. If you plan to install (or have already installed) a JDK from Sun, Kaffe, IBM or Blackdown, you are now on the right track.
When you configure PHP, you will need to add the --with-java parameter to the configuration directive, and then modify your php.ini file. The following lines are usually modified in php.ini:
[Java]
java.library.path=/path/to/library
java.class.path=/classpath/
extension_dir=/path/to/extensions
extension=libphp_java.so
However, please note that the above modifications will depend on your installation type. You should read the README file in the ext/java directory of your PHP installation to learn more about Java feature settings.
Here is a simple example: a PHP script that creates a new Java object. The script will then get certain Java properties and print them out. This is also a very good COM example.
$system = new Java("java.lang.System");
echo "
Java version = " . $system->getProperty ("java.version") . "
";
echo "Java vendor = " . $system->getProperty("java.vendor") . "