-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhpTest.java
47 lines (36 loc) · 1.38 KB
/
PhpTest.java
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import com.github.adsr.php4j.Php;
import com.github.adsr.php4j.Zval;
import java.util.Map;
public class PhpTest {
public static void main(String[] args) {
System.out.println("Initializing PHP...\n");
Php.init();
System.out.println("Requiring test.php...\n");
Zval result = Php.execString("new RuntimeException(); ");
System.out.printf("As long: %d\n\n", result.getLong());
System.out.printf("As double: %f\n\n", result.getDouble());
System.out.printf("As bool: %s\n\n", result.getBoolean());
System.out.printf("As string: %s\n\n", result.getString());
System.out.printf("As json: %s\n\n", result.getJson());
Zval[] array = result.getArray();
System.out.printf("As array: length=%d\n\n", array.length);
for (Zval e : array) {
e.dispose();
}
// TODO Fix leak
//Map<String, Zval> hash = result.getHash();
//System.out.printf("As hash: %s\n\n", hash);
//for (Zval e : hash.values()) {
// e.dispose();
//}
//Zval path = hash.get("PATH");
//if (path != null) {
// System.out.printf("key[PATH] = %s\n\n", path.getString());
// path.dispose();
//}
System.out.println("Shutting down PHP...\n");
result.dispose();
Php.shutdown();
System.out.println("Fin");
}
}