Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 05cd670d8a02b2b4a0ffb1756f2e8308 > files > 13160

php-manual-zh-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Returning Values</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="Zend API:深入 PHP 内核"
HREF="zend.html"><LINK
REL="PREVIOUS"
TITLE="Duplicating Variable Contents: The Copy Constructor"
HREF="zend.copy-constructor.html"><LINK
REL="NEXT"
TITLE="Printing Information"
HREF="zend.printing.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="sect1"
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 手册</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="zend.copy-constructor.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>章 46. Zend API:深入 PHP 内核</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="zend.printing.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="zend.returning"
>Returning Values</A
></H1
><P
>&#13;   Returning values from your functions to PHP was described briefly
   in an earlier section; this section gives the details. Return
   values are passed via the <CODE
CLASS="envar"
>return_value</CODE
> variable,
   which is passed to your functions as argument. The
   <CODE
CLASS="envar"
>return_value</CODE
> argument consists of a
   <CODE
CLASS="envar"
>zval</CODE
> container (see the earlier discussion of the
   call interface) that you can freely modify. The container itself is
   already allocated, so you don't have to run
   <TT
CLASS="literal"
>MAKE_STD_ZVAL</TT
> on it. Instead, you can access its
   members directly.
  </P
><P
>&#13;   To make returning values from functions easier and to prevent
   hassles with accessing the internal structures of the
   <CODE
CLASS="envar"
>zval</CODE
> container, a set of predefined macros is
   available (as usual). These macros automatically set the
   correspondent type and value, as described in 
   <A
HREF="zend.returning.html#tab.return"
>表 46-14</A
> and <A
HREF="zend.returning.html#tab.retval"
>表 46-15</A
>.
  </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>注意: </B
>
    The macros in <A
HREF="zend.returning.html#tab.return"
>表 46-14</A
> automatically 
    <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>return</I
></SPAN
> from your function, those in 
    <A
HREF="zend.returning.html#tab.retval"
>表 46-15</A
> only <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>set</I
></SPAN
> 
    the return value; they don't return from your function.
   </P
></BLOCKQUOTE
></DIV
><DIV
CLASS="table"
><A
NAME="tab.return"
></A
><P
><B
>表 46-14. Predefined Macros for Returning Values from a
    Function</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL
WIDTH="1*"
TITLE="col1"><COL
WIDTH="1*"
TITLE="col2"><TBODY
><TR
><TD
>Macro</TD
><TD
>Description</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>RETURN_RESOURCE(resource)</TT
></TD
><TD
>Returns a resource.</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>RETURN_BOOL(bool)</TT
></TD
><TD
>Returns a Boolean.</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>RETURN_NULL()</TT
></TD
><TD
>Returns nothing (a NULL value).</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>RETURN_LONG(long)</TT
></TD
><TD
>Returns a long.</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>RETURN_DOUBLE(double)</TT
></TD
><TD
>Returns a double.</TD
></TR
><TR
><TD
>&#13;        <TT
CLASS="literal"
>RETURN_STRING(string, duplicate)</TT
>
       </TD
><TD
>&#13;        Returns a string. The <CODE
CLASS="envar"
>duplicate</CODE
> flag indicates
        whether the string should be duplicated using
        <B
CLASS="function"
>estrdup()</B
>.
       </TD
></TR
><TR
><TD
>&#13;        <TT
CLASS="literal"
>RETURN_STRINGL(string, length, duplicate)</TT
>
       </TD
><TD
>&#13;        Returns a string of the specified length; otherwise, behaves
        like <TT
CLASS="literal"
>RETURN_STRING</TT
>. This macro is faster
        and binary-safe, however.
       </TD
></TR
><TR
><TD
><TT
CLASS="literal"
>RETURN_EMPTY_STRING()</TT
></TD
><TD
>Returns an empty string.</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>RETURN_FALSE</TT
></TD
><TD
>Returns Boolean false.</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>RETURN_TRUE</TT
></TD
><TD
>Returns Boolean true.</TD
></TR
></TBODY
></TABLE
></DIV
><DIV
CLASS="table"
><A
NAME="tab.retval"
></A
><P
><B
>表 46-15. Predefined Macros for Setting the Return Value
    of a Function</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL
WIDTH="1*"
TITLE="col1"><COL
WIDTH="1*"
TITLE="col2"><TBODY
><TR
><TD
>Macro</TD
><TD
>Description</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>RETVAL_RESOURCE(resource)</TT
></TD
><TD
>Sets the return value to the specified
        resource.</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>RETVAL_BOOL(bool)</TT
></TD
><TD
>Sets the return value to the specified
        Boolean value.</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>RETVAL_NULL</TT
></TD
><TD
>Sets the return value to NULL.</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>RETVAL_LONG(long)</TT
></TD
><TD
>&#13;        Sets the return value to the specified long.
       </TD
></TR
><TR
><TD
><TT
CLASS="literal"
>RETVAL_DOUBLE(double)</TT
></TD
><TD
>&#13;        Sets the return value to the specified double.
       </TD
></TR
><TR
><TD
>&#13;        <TT
CLASS="literal"
>RETVAL_STRING(string, duplicate)</TT
>
       </TD
><TD
>&#13;        Sets the return value to the specified string and duplicates
        it to Zend internal memory if desired (see also
        <TT
CLASS="literal"
>RETURN_STRING</TT
>).
       </TD
></TR
><TR
><TD
>&#13;        <TT
CLASS="literal"
>RETVAL_STRINGL(string, length, duplicate)</TT
>
       </TD
><TD
>&#13;        Sets the return value to the specified string and forces the
        length to become <CODE
CLASS="envar"
>length</CODE
> (see also
        <TT
CLASS="literal"
>RETVAL_STRING</TT
>). This macro is faster and
        binary-safe, and should be used whenever the string length is
        known.
       </TD
></TR
><TR
><TD
>&#13;        <TT
CLASS="literal"
>RETVAL_EMPTY_STRING</TT
>
       </TD
><TD
>&#13;        Sets the return value to an empty string.
       </TD
></TR
><TR
><TD
><TT
CLASS="literal"
>RETVAL_FALSE</TT
></TD
><TD
>&#13;        Sets the return value to Boolean false.
       </TD
></TR
><TR
><TD
><TT
CLASS="literal"
>RETVAL_TRUE</TT
></TD
><TD
>&#13;        Sets the return value to Boolean true.
       </TD
></TR
></TBODY
></TABLE
></DIV
><P
>&#13;   Complex types such as arrays and objects can be returned by using
   <A
HREF="zend-api.array-init.html"
><B
CLASS="function"
>array_init()</B
></A
> and
   <A
HREF="zend-api.object-init.html"
><B
CLASS="function"
>object_init()</B
></A
>, as well as the corresponding hash
   functions on <CODE
CLASS="envar"
>return_value</CODE
>. Since these types cannot
   be constructed of trivial information, there are no predefined
   macros for them.
  </P
></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="zend.copy-constructor.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>起始页</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="zend.printing.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Duplicating Variable Contents: The Copy Constructor</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="zend.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Printing Information</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>