Menu

[r1027]: / branches / Release-5-5-2 / php-java-bridge / tests.php5 / callback2.php  Maximize  Restore  History

Download this file

34 lines (26 with data), 944 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/php
<?php
require_once ("java/Java.inc");
function toString() {
return "php top level environment";
}
function hello($a, $b, $c) {
$a=$a?"true":"false";
return "Hello java from php: $a, $b, $c";
}
// close over the current environment and create a generic
// proxy (i.e. a proxy which defines only toString(), equals() and
// hashCode()).
$environment = java_closure();
// access $environment's invocation handler and invoke hello()
$Proxy = new JavaClass("java.lang.reflect.Proxy");
$proc = $Proxy->getInvocationHandler($environment);
// implicit toString() should display "php top level environment"
echo $environment->__toString();
// invoke java function "hello" which is backed by our php hello()
// function
echo "\ncalling ".$proc->__toString()."->invoke(...);\n";
$val = $proc->invoke($environment, "hello", array(true, 7, 3.14));
// should display "Hello java from php"
echo "=> ".($val->__toString())."\n";
?>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.