Sophie

Sophie

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

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
>php_stream_cast</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="Streams Common API Reference"
HREF="streams.common-api.html"><LINK
REL="PREVIOUS"
TITLE="php_stream_make_seekable"
HREF="streams.php-stream-make-seekable.html"><LINK
REL="NEXT"
TITLE="php_stream_can_cast"
HREF="streams.php-stream-can-cast.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="refentry"
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="streams.php-stream-make-seekable.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="streams.php-stream-can-cast.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="streams.php-stream-cast"
></A
>php_stream_cast</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN252944"
></A
>php_stream_cast&nbsp;--&nbsp;Convert a stream into another form, such as a FILE* or socket</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN252947"
></A
><H2
>Description</H2
>int <B
CLASS="methodname"
>php_stream_cast</B
> ( php_stream * stream, int castas, void ** ret, int flags )<BR
></BR
><P
>&#13;     <B
CLASS="function"
>php_stream_cast()</B
> attempts to convert <CODE
CLASS="parameter"
>stream</CODE
> into
     a resource indicated by <CODE
CLASS="parameter"
>castas</CODE
>.
     If <CODE
CLASS="parameter"
>ret</CODE
> is NULL, the stream is queried to find out if such a conversion is
     possible, without actually performing the conversion (however, some internal stream state *might*
     be changed in this case).
     If <CODE
CLASS="parameter"
>flags</CODE
> is set to <TT
CLASS="constant"
><B
>REPORT_ERRORS</B
></TT
>, an error
     message will be displayed is there is an error during conversion.
    </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>注意: </B
>
         This function returns <TT
CLASS="constant"
><B
>SUCCESS</B
></TT
> for success or <TT
CLASS="constant"
><B
>FAILURE</B
></TT
>
         for failure.  Be warned that you must explicitly compare the return value with <TT
CLASS="constant"
><B
>SUCCESS</B
></TT
>
         or <TT
CLASS="constant"
><B
>FAILURE</B
></TT
> because of the underlying values of those constants. A simple
         boolean expression will not be interpreted as you intended.
        </P
></BLOCKQUOTE
></DIV
><P
>&#13;     <DIV
CLASS="table"
><A
NAME="AEN252978"
></A
><P
><B
>表 44-1. Resource types for <CODE
CLASS="parameter"
>castas</CODE
></B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><THEAD
><TR
><TH
>Value</TH
><TH
>Meaning</TH
></TR
></THEAD
><TBODY
><TR
><TD
>PHP_STREAM_AS_STDIO</TD
><TD
>Requests an ANSI FILE* that represents the stream</TD
></TR
><TR
><TD
>PHP_STREAM_AS_FD</TD
><TD
>Requests a POSIX file descriptor that represents the stream</TD
></TR
><TR
><TD
>PHP_STREAM_AS_SOCKETD</TD
><TD
>Requests a network socket descriptor that represents the stream</TD
></TR
></TBODY
></TABLE
></DIV
>
    </P
><P
>&#13;     In addition to the basic resource types above, the conversion process can be altered by using the
     following flags by using the OR operator to combine the resource type with one or more of the
     following values:
     <DIV
CLASS="table"
><A
NAME="AEN252997"
></A
><P
><B
>表 44-2. Resource types for <CODE
CLASS="parameter"
>castas</CODE
></B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><THEAD
><TR
><TH
>Value</TH
><TH
>Meaning</TH
></TR
></THEAD
><TBODY
><TR
><TD
>PHP_STREAM_CAST_TRY_HARD</TD
><TD
>Tries as hard as possible, at the expense of additional resources, to ensure that the conversion succeeds</TD
></TR
><TR
><TD
>PHP_STREAM_CAST_RELEASE</TD
><TD
>Informs the streams API that some other code (possibly a third party library) will be responsible for closing the
         underlying handle/resource.  This causes the <CODE
CLASS="parameter"
>stream</CODE
> to be closed in such a way the underlying
         handle is preserved and returned in <CODE
CLASS="parameter"
>ret</CODE
>.  If this function succeeds, <CODE
CLASS="parameter"
>stream</CODE
>
         should be considered closed and should no longer be used.
         </TD
></TR
></TBODY
></TABLE
></DIV
>
    </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>注意: </B
>
      If your system supports <B
CLASS="function"
>fopencookie()</B
> (systems using glibc 2 or later), the streams API
      will always be able to synthesize an ANSI FILE* pointer over any stream.
      While this is tremendously useful for passing any PHP stream to any third-party libraries, such behaviour is not
      portable.  You are requested to consider the portability implications before distributing you extension.
      If the fopencookie synthesis is not desirable, you should query the stream to see if it naturally supports FILE*
      by using <B
CLASS="function"
>php_stream_is()</B
>
     </P
></BLOCKQUOTE
></DIV
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>注意: </B
>
      If you ask a socket based stream for a FILE*, the streams API will use <B
CLASS="function"
>fdopen()</B
> to
      create it for you.  Be warned that doing so may cause data that was buffered in the streams layer to be
      lost if you intermix streams API calls with ANSI stdio calls.
     </P
></BLOCKQUOTE
></DIV
><P
>&#13;     See also <B
CLASS="function"
>php_stream_is()</B
> and <B
CLASS="function"
>php_stream_can_cast()</B
>.
    </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="streams.php-stream-make-seekable.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="streams.php-stream-can-cast.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>php_stream_make_seekable</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="streams.common-api.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>php_stream_can_cast</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>