Monday, August 31, 2009

PHP Welcome Java


Java Integration with php is a lot easier with PHP/JAVA Bridge.


INTRODUCTION




The PHP/Java Bridge is an implementation of a streaming, XML-based network protocol, which can be used to connect a native script engine, for example PHP, Scheme or Python, with a Java or ECMA 335 virtual machine. It is more than 50 times faster than local RPC via SOAP, requires less resources on the web-server side. It is faster and more reliable than direct communication via the Java Native Interface, and it requires no additional components to invoke Java procedures from PHP or PHP procedures from Java. Download it from: PHP/JAVA BRIDGE


PHP/Java integration


The Java.inc PHP library sets up an autoload handler to import Java into PHP's environment. The following example autoloads the standard Java classes from Java and makes them available to PHP.


<?php
use java\lang\String as JString;
use java\lang\ArrayList as JList;

class String extends JString {
function toString () {
return "hello " . parent::toString();
}
}
$str = new String("Java");

$list = new JList();
$list->add (java_closure($str));
$list->add ("from PHP");
$ar = java_values ($list->toArray());

var_dump($ar);
?>

=>array ["hello Java", "from PHP"]



It makes use of the syntax transformer built into PHP 5.3 and above to import and extend the functionality of Java classes. In the above example java.lang.String is extended by a PHP class, overriding the functionality of its toString() method. An instance of this class is then passed to a java.lang.ArrayList. The entire list is then converted into a PHP scalar value using java_values.


No comments:

Post a Comment

All rights are reserved. Nobleatom.com
Software Development Services.
Contact me: khubabmazhar596@hotmail.com

Web Design Increase Page Rank Internet blogs DigNow.net web directory1Abc DirectorySeo friendly web directory