mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Some tweaking.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@50880 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
947ebedad4
commit
42bc6286ae
1 changed files with 31 additions and 28 deletions
|
@ -4,36 +4,36 @@
|
|||
<partintro>
|
||||
<para>
|
||||
There are two possible ways to bridge PHP and Java: you can either
|
||||
integrate Java into PHP, which is the more stable and efficient
|
||||
solution, or integrate PHP into a Java Servlet environment.
|
||||
The former is provided by ext/java, the latter by a SAPI module that
|
||||
interfaces with the Servlet server.
|
||||
integrate PHP into a Java Servlet environment, which is the more
|
||||
stable and efficient solution, or integrate Java support into PHP.
|
||||
The former is provided by a SAPI module that interfaces with the
|
||||
Servlet server, the latter by the Java extension.
|
||||
</para>
|
||||
<para>
|
||||
PHP 4 ext/java provides a simple and effective means for creating and
|
||||
invoking methods on Java objects from PHP. The JVM is created using JNI,
|
||||
and everything runs in-process. Build instructions for ext/java can be
|
||||
found in php4/ext/java/README.
|
||||
found in <filename>php4/ext/java/README</filename>.
|
||||
|
||||
<example>
|
||||
<title>Java Example</title>
|
||||
<programlisting role="php">
|
||||
<?php
|
||||
// get instance of Java class java.lang.System in PHP
|
||||
$system = new Java("java.lang.System");
|
||||
$system = new Java('java.lang.System');
|
||||
|
||||
// demonstrate property access
|
||||
print "Java version=".$system->getProperty("java.version")." <br>";
|
||||
print "Java vendor=" .$system->getProperty("java.vendor")." <br>";
|
||||
print "OS=".$system->getProperty("os.name")." ".
|
||||
$system->getProperty("os.version")." on ".
|
||||
$system->getProperty("os.arch")." <br>";
|
||||
print 'Java version='.$system->getProperty('java.version').' <br>';
|
||||
print 'Java vendor=' .$system->getProperty('java.vendor').' <br>';
|
||||
print 'OS='.$system->getProperty('os.name').' '.
|
||||
$system->getProperty('os.version').' on '.
|
||||
$system->getProperty('os.arch').' <br>';
|
||||
|
||||
// java.util.Date example
|
||||
$formatter = new Java("java.text.SimpleDateFormat",
|
||||
$formatter = new Java('java.text.SimpleDateFormat',
|
||||
"EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz");
|
||||
|
||||
print $formatter->format(new Java("java.util.Date"));
|
||||
print $formatter->format(new Java('java.util.Date'));
|
||||
?>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
@ -43,15 +43,15 @@
|
|||
<?php
|
||||
// This example is only intented to be run as a CGI.
|
||||
|
||||
$frame = new Java("java.awt.Frame", "Zend");
|
||||
$button = new Java("java.awt.Button", "Hello Java world!");
|
||||
$frame = new Java('java.awt.Frame', 'PHP');
|
||||
$button = new Java('java.awt.Button', 'Hello Java World!');
|
||||
|
||||
$frame->add("North", $button);
|
||||
$frame->add('North', $button);
|
||||
$frame->validate();
|
||||
$frame->pack();
|
||||
$frame->visible = True;
|
||||
|
||||
$thread = new Java("java.lang.Thread");
|
||||
$thread = new Java('java.lang.Thread');
|
||||
$thread->sleep(10000);
|
||||
|
||||
$frame->dispose();
|
||||
|
@ -64,25 +64,27 @@
|
|||
<itemizedlist>
|
||||
<listitem>
|
||||
<simpara>
|
||||
new Java() will create an instance of a class if a suitable constructor
|
||||
is available. If no parameters are passed and the default constructor
|
||||
is useful as it provides access to classes like "java.lang.System"
|
||||
which expose most of their functionallity through static methods.
|
||||
<literal>new Java()</literal> will create an instance of a class if
|
||||
a suitable constructor is available. If no parameters are passed and
|
||||
the default constructor is useful as it provides access to classes
|
||||
like <literal>java.lang.System</literal> which expose most of their
|
||||
functionallity through static methods.
|
||||
</simpara>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<simpara>
|
||||
Accessing a member of an instance will first look for bean properties
|
||||
then public fields. In other words, "print $date.time" will first
|
||||
attempt to be resolved as "$date.getTime()", then as "$date.time";
|
||||
then public fields. In other words, <literal>print $date.time</literal>
|
||||
will first attempt to be resolved as <literal>$date.getTime()</literal>,
|
||||
then as <literal>$date.time</literal>.
|
||||
</simpara>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<simpara>
|
||||
Both static and instance members can be accessed on an object with
|
||||
the same syntax. Furthermore, if the java object is of type
|
||||
"java.lang.Class", then static members of the class (fields and
|
||||
methods) can be accessed.
|
||||
<literal>java.lang.Class</literal>, then static members of the class
|
||||
(fields and methods) can be accessed.
|
||||
</simpara>
|
||||
</listitem>
|
||||
<listitem>
|
||||
|
@ -125,11 +127,12 @@
|
|||
</itemizedlist>
|
||||
</para>
|
||||
<para>
|
||||
PHP4 sapi/servlet builds upon the mechanism defined by ext/java to enable
|
||||
sapi/servlet builds upon the mechanism defined by ext/java to enable
|
||||
the entire PHP processor to be run as a servlet. The primary advanatage
|
||||
of this from a PHP perspective is that web servers which support servlets
|
||||
typically take great care in pooling and reusing JVMs. Build instructions
|
||||
for the Servlet SAPI module can be found in php4/sapi/README.
|
||||
for the Servlet SAPI module can be found in
|
||||
<filename>php4/sapi/README</filename>.
|
||||
|
||||
Notes:
|
||||
|
||||
|
@ -192,7 +195,7 @@
|
|||
<title>Java exception handler</title>
|
||||
<programlisting role="php">
|
||||
<?php
|
||||
$stack = new Java("java.util.Stack");
|
||||
$stack = new Java('java.util.Stack');
|
||||
$stack->push(1);
|
||||
|
||||
// This should succeed
|
||||
|
|
Loading…
Reference in a new issue