Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > media > main > by-pkgid > 0afeee9cca140e167a996902b9a677c5 > files > 3093

php-manual-en-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>PHP / Java Integration</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="PHP Manual"
HREF="index.html"><LINK
REL="UP"
TITLE="Function Reference"
HREF="funcref.html"><LINK
REL="PREVIOUS"
TITLE="ircg_whois"
HREF="function.ircg-whois.html"><LINK
REL="NEXT"
TITLE="java_last_exception_clear"
HREF="function.java-last-exception-clear.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=ISO-8859-1"></HEAD
><BODY
CLASS="reference"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.ircg-whois.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.java-last-exception-clear.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="reference"
><A
NAME="ref.java"
></A
><DIV
CLASS="TITLEPAGE"
><H1
CLASS="title"
>XLVII. PHP / Java Integration</H1
><DIV
CLASS="PARTINTRO"
><A
NAME="AEN42262"
></A
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="java.intro"
></A
>Introduction</H1
><P
>&#13;     There are two possible ways to bridge PHP and Java: you can either 
     <A
HREF="ref.java.html#java.servlet"
>integrate PHP into a Java Servlet
     environment</A
>, 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 this
     Java extension.
    </P
><P
>&#13;     The Java extension 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.
    </P
><DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
BORDER="1"
WIDTH="100%"
><TR
><TD
ALIGN="CENTER"
><B
>Warning</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
><P
>This extension is
<SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>EXPERIMENTAL</I
></SPAN
>. The behaviour of this extension --
including the names of its functions and anything else documented
about this extension -- may change without notice in a future release of PHP. 
Use this extension at your own risk.</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="java.requirements"
></A
>Requirements</H1
><P
>&#13;     You need a Java VM installed on your machine to use this extension.
    </P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="java.installation"
></A
>Installation</H1
><P
>&#13;  To include Java support in your PHP build you must add the option
  <TT
CLASS="option"
>--with-java[=DIR]</TT
> where DIR points
  to the base install directory of your JDK. This extension can only be built
  as a shared dl. More build instructions for this extension can be found in
  <TT
CLASS="filename"
>php4/ext/java/README</TT
>.
 </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note to Win32 Users: </B
>
   In order to enable this module on a Windows environment, you must copy
   <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>jvm.dll</I
></SPAN
> from the DLL folder of the PHP/Win32 binary
   package to the SYSTEM32 folder of your windows machine. (Ex:C:\WINNT\SYSTEM32
   or C:\WINDOWS\SYSTEM32)
  </P
></BLOCKQUOTE
></DIV
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="java.configuration"
></A
>Runtime Configuration</H1
><P
>&#13;The behaviour of these functions is affected by settings in <TT
CLASS="filename"
>php.ini</TT
>.
</P
><P
>&#13; <DIV
CLASS="table"
><A
NAME="AEN42288"
></A
><P
><B
>Table 1. Java configuration options</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Name</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Default</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Changeable</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>java.class.path</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>NULL</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>PHP_INI_ALL</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>java.home</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>NULL</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>PHP_INI_ALL</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>java.library.path</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>NULL</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>PHP_INI_ALL</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>java.library</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>JAVALIB</TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>PHP_INI_ALL</TD
></TR
></TBODY
></TABLE
></DIV
>
 For further details and definition of the PHP_INI_* constants see
 <A
HREF="function.ini-set.html"
><B
CLASS="function"
>ini_set()</B
></A
>.
 </P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="java.resources"
></A
>Resource Types</H1
><P
>This extension has no resource types defined.</P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="java.constants"
></A
>Predefined Constants</H1
><P
>This extension has no constants defined.</P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="java.examples"
></A
>Examples</H1
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN42323"
></A
><P
><B
>Example 1. Java Example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php
  // get instance of Java class java.lang.System in PHP
  $system = new Java('java.lang.System');

  // demonstrate property access
  print 'Java version='.$system-&#62;getProperty('java.version').' &#60;br&#62;';
  print 'Java vendor=' .$system-&#62;getProperty('java.vendor').' &#60;br&#62;';
  print 'OS='.$system-&#62;getProperty('os.name').' '.
              $system-&#62;getProperty('os.version').' on '.
              $system-&#62;getProperty('os.arch').' &#60;br&#62;';

  // java.util.Date example
  $formatter = new Java('java.text.SimpleDateFormat',
                        "EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz");

  print $formatter-&#62;format(new Java('java.util.Date'));
?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN42326"
></A
><P
><B
>Example 2. AWT Example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php
  // This example is only intented to be run as a CGI.

  $frame  = new Java('java.awt.Frame', 'PHP');
  $button = new Java('java.awt.Button', 'Hello Java World!');

  $frame-&#62;add('North', $button);
  $frame-&#62;validate();
  $frame-&#62;pack();
  $frame-&#62;visible = True;

  $thread = new Java('java.lang.Thread');
  $thread-&#62;sleep(10000);

  $frame-&#62;dispose();
?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>

     Notes:

     <P
></P
><UL
><LI
><P
>&#13;        <TT
CLASS="literal"
>new Java()</TT
> 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 <TT
CLASS="literal"
>java.lang.System</TT
> which expose most of their 
        functionallity through static methods.
       </P
></LI
><LI
><P
>&#13;        Accessing a member of an instance will first look for bean properties
        then public fields. In other words, <TT
CLASS="literal"
>print $date.time</TT
>
        will first attempt to be resolved as <TT
CLASS="literal"
>$date.getTime()</TT
>,
        then as <TT
CLASS="literal"
>$date.time</TT
>.
       </P
></LI
><LI
><P
>&#13;        Both static and instance members can be accessed on an object with
        the same syntax. Furthermore, if the java object is of type
        <TT
CLASS="literal"
>java.lang.Class</TT
>, then static members of the class 
        (fields and methods) can be accessed.
       </P
></LI
><LI
><P
>&#13;        Exceptions raised result in PHP warnings, and <TT
CLASS="constant"
><B
>NULL</B
></TT
> results. The
        warnings may be eliminated by prefixing the method call with an
        "@" sign. The following APIs may be used to retrieve and reset
        the last error:
        <P
></P
><UL
><LI
><P
><A
HREF="function.java-last-exception-get.html"
><B
CLASS="function"
>java_last_exception_get()</B
></A
></P
></LI
><LI
><P
><A
HREF="function.java-last-exception-clear.html"
><B
CLASS="function"
>java_last_exception_clear()</B
></A
></P
></LI
></UL
>
       </P
></LI
><LI
><P
>&#13;        Overload resolution is in general a hard problem given the
        differences in types between the two languages. The PHP Java
        extension employs a simple, but fairly effective, metric for
        determining which overload is the best match.
       </P
><P
>&#13;        Additionally, method names in PHP are not case sensitive, potentially
        increasing the number of overloads to select from.
       </P
><P
>&#13;        Once a method is selected, the parameters are cooerced if necessary, 
        possibly with a loss of data (example: double precision floating point
        numbers will be converted to boolean).
        
       </P
></LI
><LI
><P
>&#13;        In the tradition of PHP, arrays and hashtables may pretty much
        be used interchangably. Note that hashtables in PHP may only be
        indexed by integers or strings; and that arrays of primitive types
        in Java can not be sparse. Also note that these constructs are
        passed by value, so may be expensive in terms of memory and time.
       </P
></LI
></UL
>
    </P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="java.servlet"
></A
>Java Servlet SAPI</H1
><P
>&#13;     The Java Servlet SAPI builds upon the mechanism defined by the Java
     extension 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 
     <TT
CLASS="filename"
>php4/sapi/README</TT
>.

     Notes:

     <P
></P
><UL
><LI
><P
>&#13;        While this code is intended to be able to run on any servlet engine,
        it has only been tested on Apache's Jakarta/tomcat to date. Bug
        reports, success stories and/or patches required to get this code
        to run on other engines would be appreciated.
       </P
></LI
><LI
><P
>&#13;        PHP has a habit of changing the working directory. sapi/servlet will
        eventually change it back, but while PHP is running the servlet engine
        may not be able to load any classes from the CLASSPATH which are
        specified using a relative directory syntax, or find the work directory
        used for administration and JSP compilation tasks.
       </P
></LI
></UL
>
    </P
></DIV
></DIV
><DIV
CLASS="TOC"
><DL
><DT
><B
>Table of Contents</B
></DT
><DT
><A
HREF="function.java-last-exception-clear.html"
>java_last_exception_clear</A
>&nbsp;--&nbsp;Clear last Java exception</DT
><DT
><A
HREF="function.java-last-exception-get.html"
>java_last_exception_get</A
>&nbsp;--&nbsp;Get last Java exception</DT
></DL
></DIV
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.ircg-whois.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.java-last-exception-clear.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>ircg_whois</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="funcref.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>java_last_exception_clear</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>