ch07s01.html.svn-base

来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· SVN-BASE 代码 · 共 48 行 · 第 1/2 页

SVN-BASE
48
字号
<html><head>      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">   <title>1.&nbsp;xmlrpcval</title><link rel="stylesheet" href="html.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.71.1"><link rel="start" href="index.html" title="XML-RPC for PHP"><link rel="up" href="ch07.html" title="Chapter&nbsp;7.&nbsp;Class documentation"><link rel="prev" href="ch07.html" title="Chapter&nbsp;7.&nbsp;Class documentation"><link rel="next" href="ch07s02.html" title="2.&nbsp;xmlrpcmsg"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">1.&nbsp;xmlrpcval</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch07.html">Prev</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;7.&nbsp;Class documentation</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="ch07s02.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="xmlrpcval"></a>1.&nbsp;xmlrpcval</h2></div></div></div><p>This is where a lot of the hard work gets done. This class enables the creation and encapsulation of values for XML-RPC.</p><p>Ensure you've read the XML-RPC spec at <a href="http://www.xmlrpc.com/stories/storyReader$7" target="_top">http://www.xmlrpc.com/stories/storyReader$7</a> before reading on as it will make things clearer.</p><p>The <code class="classname">xmlrpcval</code> class can store arbitrarily complicated values using the following types: <code class="literal">i4 int boolean string double dateTime.iso8601 base64 array struct</code>. You should refer to the <a href="http://www.xmlrpc.com/spec" target="_top">spec</a> for more information on what each of these types mean.</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e815"></a>1.1.&nbsp;Notes on types</h3></div></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e818"></a>1.1.1.&nbsp;int</h4></div></div></div><p>The type <code class="classname">i4</code> is accepted as a synonym for <code class="classname">int</code> when creating xmlrpcval objects. The xml parsing code will always convert <code class="classname">i4</code> to <code class="classname">int</code>: <code class="classname">int</code> is regarded by this implementation as the canonical name for this type.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e838"></a>1.1.2.&nbsp;base64</h4></div></div></div><p>Base 64 encoding is performed transparently to the caller when using this type. Decoding is also transparent. Therefore you ought to consider it as a "binary" data type, for use when you want to pass data that is not 7-bit clean.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e843"></a>1.1.3.&nbsp;boolean</h4></div></div></div><p>The php values <code class="literal">true</code> and <code class="literal">1</code> map to <code class="literal">true</code>. All other values (including the empty string) are converted to <code class="literal">false</code>.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e860"></a>1.1.4.&nbsp;string</h4></div></div></div><p>Characters &lt;, &gt;, ', ", &amp;, are encoded using their entity reference as &amp;lt; &amp;gt; &amp;apos; &amp;quot; and &amp;amp; All other characters outside of the ASCII range are encoded using their character reference representation (e.g. &amp;#200 for &eacute;). The XML-RPC spec recommends only encoding <code class="literal">&lt; &amp;</code> but this implementation goes further, for reasons explained by <a href="http://www.w3.org/TR/REC-xml#syntax" target="_top">the XML 1.0 recommendation</a>. In particular, using character reference representation has the advantage of producing XML that is valid independently of the charset encoding assumed.</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="xmlrpcval-creation"></a>1.2.&nbsp;Creation</h3></div></div></div><p>The constructor is the normal way to create an <code class="classname">xmlrpcval</code>. The constructor can take these forms:</p><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">$myVal = new <b class="fsfunc">xmlrpcval</b>(</code></td><td><code>)</code>;</td><td>&nbsp;</td></tr></table><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">$myVal = new <b class="fsfunc">xmlrpcval</b>(</code></td><td><var class="pdparam">$stringVal</var><code>)</code>;</td><td>&nbsp;</td></tr></table><table border="0" summary="Function argument synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code>string</code>&nbsp;</td><td><code><var class="pdparam">$stringVal</var>;</code></td></tr></table><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">$myVal = new <b class="fsfunc">xmlrpcval</b>(</code></td><td><var class="pdparam">$scalarVal</var>, </td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td><var class="pdparam">$scalartyp</var><code>)</code>;</td><td>&nbsp;</td></tr></table><table border="0" summary="Function argument synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code>mixed</code>&nbsp;</td><td><code><var class="pdparam">$scalarVal</var>;</code></td></tr><tr><td><code>string</code>&nbsp;</td><td><code><var class="pdparam">$scalartyp</var>;</code></td></tr></table><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">$myVal = new <b class="fsfunc">xmlrpcval</b>(</code></td><td><var class="pdparam">$arrayVal</var>, </td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td><var class="pdparam">$arraytyp</var><code>)</code>;</td><td>&nbsp;</td></tr></table><table border="0" summary="Function argument synopsis" cellspacing="0" cellpadding="0"><tr><td><code>array</code>&nbsp;</td><td><code><var class="pdparam">$arrayVal</var>;</code></td></tr><tr><td><code>string</code>&nbsp;</td><td><code><var class="pdparam">$arraytyp</var>;</code></td></tr></table></div><p>The first constructor creates an empty value, which must be altered using the methods <code class="function">addScalar</code>, <code class="function">addArray</code> or <code class="function">addStruct</code> before it can be used.</p><p>The second constructor creates a simple string value.</p><p>The third constructor is used to create a scalar value. The second parameter must be a name of an XML-RPC type. Valid types are: "<code class="literal">int</code>", "<code class="literal">boolean</code>", "<code class="literal">string</code>", "<code class="literal">double</code>", "<code class="literal">dateTime.iso8601</code>", "<code class="literal">base64</code>".</p><p>Examples:</p><pre class="programlisting">$myInt = new xmlrpcvalue(1267, "int");$myString = new xmlrpcvalue("Hello, World!", "string");$myBool = new xmlrpcvalue(1, "boolean");$myString2 = new xmlrpcvalue(1.24, "string"); // note: this will serialize a php float value as xmlrpc string</pre><p>The fourth constructor form can be used to compose complex XML-RPC values. The first argument is either a simple array in the case of an XML-RPC <code class="classname">array</code> or an associative array in the case of a <code class="classname">struct</code>. The elements of the array <span class="emphasis"><em>must be <code class="classname">xmlrpcval</code> objects themselves</em></span>.</p><p>The second parameter must be either "<code class="literal">array</code>" or "<code class="literal">struct</code>".</p><p>Examples:</p><pre class="programlisting">$myArray = new xmlrpcval(  array(    new xmlrpcval("Tom"),    new xmlrpcval("Dick"),    new xmlrpcval("Harry")  ),  "array");// recursive struct$myStruct = new xmlrpcval(  array(    "name" =&gt; new xmlrpcval("Tom", "string"),    "age" =&gt; new xmlrpcval(34, "int"),    "address" =&gt; new xmlrpcval(      array(

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?