Building Web Applications Using PHP and Java
The PHP/Java bridge allows you to quickly access Java classes from within your PHP classes without having to know Java and vice versa. Because of this two-way flexibility, you can access hundreds of pre-built Java classes from PHP, and hundreds of pre-built PHP classes from Java opening up your applications to greater flexibility and enhanced functionality.
Zend Platform Java Bridge is the commercial alternative to PHP/Java Bridge.
Zend Platform Java Bridge
Zend Platform Java Bridge is the leading performance and reliability solution for businesses that seek to utilize both PHP and Java/J2EE.
Based on a unique design that allows for a single Java Virtual Machine (JVM) instantiation and direct calls from PHP, the Java Bridge delivers unprecedented performance and scalability that make true PHP and Java integration a reality.
Java Bridge code can be run and debugged in the same way as normal PHP code.
Java Bridge Functionality
Java Bridge provides four main functions:
1. Function invocation
Java Bridge provides code completion for the following Java functions/methods:
- java_get_statistics() – Get Java server statistics
- java_get_version_info() – Get Java extension version information
- java_last_exception_clear() – Clear last Java exception
- java_last_exception_get() – Get last Java exception
- java_set_encoding() – Set encoding for PHP-Java data transfers
- java_set_ignore_case() – Set if search for Java classes and methods should be case-insensitive
- java_throw_exceptions() – Set if exceptions should be thrown on errors
2. Java instantiation: Creates new Java-PHP Objects
Zend Studio for Eclipse supports Java Object instances. After instantiation of a PHP Java object, the PHP variable it was assigned to assumes the properties and methods of the Java class. This allows the object to implement Java functionality, as well as allowing access to Java’s Code Assist options.
Assignments attach the resulting Java object to the PHP variable.
/**
* Java Bridge instantiation
*/
$firstService = new java("com.zend.FirstService");
$secondService = new java("com.zend.SecondService");
3. Java Exception handling: Catching Java exceptions
Java exceptions can be caught by Zend Studio for Eclipse using Java Bridge.
/**
* Java exception handling
*/
try {
$a = new java("java.io.File");
$a->doSomething();
// java invocations
} catch (JavaException $e) {
print "problem with java execution...";
print $e->getCause();
}
4. Automatic Type Conversion
The Java Bridge will also perform the following conversions to PHP objects when Java objects are returned:

[...] building-web-applications-using-php-and-java/ [...]
Building Web Applications Using PHP and Java
June 2, 2008 at 4:37 pm
[...] Building Web Applications Using PHP and Java (0 visite) [...]
To take away
June 4, 2008 at 5:23 pm
[...] Building Web Applications Using PHP and Java (0 visite) [...]
To take away
June 4, 2008 at 9:30 pm
hey, thanks for the info. also, do you know how i can call a php function from a java application? a working example would help a lot. thanks much!
yugan
December 4, 2008 at 2:36 pm
Another place to look at is projectzero. See http://www.projectzero.org/php The Project zero java bridge is quite sophisticated. It can even extend Java Classes in PHP.
Rob Nicholson
February 3, 2009 at 6:01 am
Thanks for the information. Please examples of using PHP/Java Bridge and what need to be done for this two application to work properly will be of more help.
once again well done.
Kayode
February 10, 2009 at 1:29 am
hi,
thanks for such a great article.
solved my jsp to php project migration problem
thanks….
Abhijeet
March 8, 2010 at 6:09 am
hi! i am sujoy ..i want to know that—-i have implemented a web application in j2ee(chat application) and my friend has implemented a web page ,,my query is that can i make a project using both of them in a same platform through bridging???plss reply
sujoy biswas
November 25, 2010 at 5:01 am