ch07s01.html.svn-base

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

SVN-BASE
48
字号
        "street" =&gt; new xmlrpcval("Fifht Ave", "string"),        "city" =&gt; new xmlrpcval("NY", "string")      ),       "struct")  ),   "struct");</pre><p>See the file <code class="literal">vardemo.php</code> in this distribution for more examples.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="xmlrpcval-methods"></a>1.3.&nbsp;Methods</h3></div></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e997"></a>1.3.1.&nbsp;addScalar</h4></div></div></div><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">$ok = $val-&gt;<b class="fsfunc">addScalar</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">$ok = $val-&gt;<b class="fsfunc">addScalar</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"><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></div><p>If <em class="parameter"><code>$val</code></em> is an empty <code class="classname">xmlrpcval</code> this method makes it a scalar value, and sets that value.</p><p>If <em class="parameter"><code>$val</code></em> is already a scalar value, then no more scalars can be added and <code class="literal">0</code> is returned.</p><p>If <em class="parameter"><code>$val</code></em> is an xmlrpcval of type array, the php value <em class="parameter"><code>$scalarval</code></em> is added as its last element.</p><p>If all went OK, <code class="literal">1</code> is returned, otherwise <code class="literal">0</code>.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1058"></a>1.3.2.&nbsp;addArray</h4></div></div></div><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">$ok = $val-&gt;<b class="fsfunc">addArray</b>(</code></td><td><var class="pdparam">$arrayVal</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></table></div><p>The argument is a simple (numerically indexed) array. The elements of the array <span class="emphasis"><em>must be <code class="classname">xmlrpcval</code> objects themselves</em></span>.</p><p>Turns an empty <code class="classname">xmlrpcval</code> into an <code class="classname">array</code> with contents as specified by <em class="parameter"><code>$arrayVal</code></em>.</p><p>If <em class="parameter"><code>$val</code></em> is an xmlrpcval of type array, the elements of <em class="parameter"><code>$arrayVal</code></em> are appended to the existing ones.</p><p>See the fourth constructor form for more information.</p><p>If all went OK, <code class="literal">1</code> is returned, otherwise <code class="literal">0</code>.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1109"></a>1.3.3.&nbsp;addStruct</h4></div></div></div><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">$ok = $val-&gt;<b class="fsfunc">addStruct</b>(</code></td><td><var class="pdparam">$assocArrayVal</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">$assocArrayVal</var>;</code></td></tr></table></div><p>The argument is an associative array. The elements of the array <span class="emphasis"><em>must be <code class="classname">xmlrpcval</code> objects themselves</em></span>.</p><p>Turns an empty <code class="classname">xmlrpcval</code> into a <code class="classname">struct</code> with contents as specified by <em class="parameter"><code>$assocArrayVal</code></em>.</p><p>If <em class="parameter"><code>$val</code></em> is an xmlrpcval of type struct, the elements of <em class="parameter"><code>$arrayVal</code></em> are merged with the existing ones.</p><p>See the fourth constructor form for more information.</p><p>If all went OK, <code class="literal">1</code> is returned, otherwise <code class="literal">0</code>.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1160"></a>1.3.4.&nbsp;kindOf</h4></div></div></div><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">$kind = $val-&gt;<b class="fsfunc">kindOf</b>(</code></td><td><code>)</code>;</td><td>&nbsp;</td></tr></table></div><p>Returns a string containing "struct", "array" or "scalar" describing the base type of the value. If it returns "undef" it means that the value hasn't been initialised.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1172"></a>1.3.5.&nbsp;serialize</h4></div></div></div><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">$outString = $val-&gt;<b class="fsfunc">serialize</b>(</code></td><td><code>)</code>;</td><td>&nbsp;</td></tr></table></div><p>Returns a string containing the XML-RPC representation of this value.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1184"></a>1.3.6.&nbsp;scalarVal</h4></div></div></div><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">$scalarVal = $val-&gt;<b class="fsfunc">scalarVal</b>(</code></td><td><code>)</code>;</td><td>&nbsp;</td></tr></table></div><p>If <code class="function">$val-&gt;kindOf() == "scalar"</code>, this method returns the actual PHP-language value of the scalar (base 64 decoding is automatically handled here).</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1199"></a>1.3.7.&nbsp;scalarTyp</h4></div></div></div><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">$typeName = $val-&gt;<b class="fsfunc">scalarTyp</b>(</code></td><td><code>)</code>;</td><td>&nbsp;</td></tr></table></div><p>If <code class="function">$val-&gt;kindOf() == "scalar"</code>, this method returns a string denoting the type of the scalar. As mentioned before, <code class="literal">i4</code> is always coerced to <code class="literal">int</code>.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1220"></a>1.3.8.&nbsp;arrayMem</h4></div></div></div><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">$xmlrpcVal = $val-&gt;<b class="fsfunc">arrayMem</b>(</code></td><td><var class="pdparam">$n</var><code>)</code>;</td><td>&nbsp;</td></tr></table><table border="0" summary="Function argument synopsis" cellspacing="0" cellpadding="0"><tr><td><code>int</code>&nbsp;</td><td><code><var class="pdparam">$n</var>;</code></td></tr></table></div><p>If <code class="function">$val-&gt;kindOf() == "array"</code>, returns the <em class="parameter"><code>$n</code></em>th element in the array represented by the value <em class="parameter"><code>$val</code></em>. The value returned is an <code class="classname">xmlrpcval</code> object.</p><pre class="programlisting">// iterating over values of an array objectfor ($i = 0; $i &lt; $val-&gt;arraySize(); $i++){  $v = $val-&gt;arrayMem($i);  echo "Element $i of the array is of type ".$v-&gt;kindOf();}</pre></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1251"></a>1.3.9.&nbsp;arraySize</h4></div></div></div><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">$len = $val-&gt;<b class="fsfunc">arraySize</b>(</code></td><td><code>)</code>;</td><td>&nbsp;</td></tr></table></div><p>If <em class="parameter"><code>$val</code></em> is an <code class="classname">array</code>, returns the number of elements in that array.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1269"></a>1.3.10.&nbsp;structMem</h4></div></div></div><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">$xmlrpcVal = $val-&gt;<b class="fsfunc">structMem</b>(</code></td><td><var class="pdparam">$memberName</var><code>)</code>;</td><td>&nbsp;</td></tr></table><table border="0" summary="Function argument synopsis" cellspacing="0" cellpadding="0"><tr><td><code>string</code>&nbsp;</td><td><code><var class="pdparam">$memberName</var>;</code></td></tr></table></div><p>If <code class="function">$val-&gt;kindOf() == "struct"</code>, returns the element called <em class="parameter"><code>$memberName</code></em> from the struct represented by the value <em class="parameter"><code>$val</code></em>. The value returned is an <code class="classname">xmlrpcval</code> object.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="d0e1297"></a>1.3.11.&nbsp;structEach</h4></div></div></div><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">list($key, $value) = $val-&gt;<b class="fsfunc">structEach</b>(</code></td><td><code>)</code>;</td><td>&nbsp;</td></tr></table></div><p>Returns the next (key, value) pair from the struct, when <em class="parameter"><code>$val</code></em> is a struct. <em class="parameter"><code>$value</code></em> is an xmlrpcval itself. See also <a href="ch07s01.html#structreset">structreset()</a>.</p><pre class="programlisting">// iterating over all values of a struct object$val-&gt;structreset();while (list($key, $v) = $val-&gt;structEach()){  echo "Element $key of the struct is of type ".$v-&gt;kindOf();}</pre></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="structreset"></a>1.3.12.&nbsp;structReset</h4></div></div></div><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">$val-&gt;<b class="fsfunc">structReset</b>(</code></td><td><code>)</code>;</td><td>&nbsp;</td></tr></table></div><p>Resets the internal pointer for <code class="function">structEach()</code> to the beginning of the struct, where <em class="parameter"><code>$val</code></em> is a struct.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="structmemexists"></a>1.3.13.&nbsp;structMemExists</h4></div></div></div><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">$exists = $val-&gt;<b class="fsfunc">structMemExsists</b>(</code></td><td><var class="pdparam">$memberName</var><code>)</code>;</td><td>&nbsp;</td></tr></table><table border="0" summary="Function argument synopsis" cellspacing="0" cellpadding="0"><tr><td><code>string</code>&nbsp;</td><td><code><var class="pdparam">$memberName</var>;</code></td></tr></table></div><p>Returns <code class="constant">TRUE</code> or <code class="constant">FALSE</code> depending on whether a member of the given name exists in the struct.</p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch07.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="ch07.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="ch07s02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter&nbsp;7.&nbsp;Class documentation&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;2.&nbsp;xmlrpcmsg</td></tr></table></div></body></html>

⌨️ 快捷键说明

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