mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-17 21:16:57 +08:00
123 lines
5.5 KiB
HTML
123 lines
5.5 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
<title>Return the traits used by the given class</title>
|
|
</head>
|
|
<body class="docs"><div id="layout">
|
|
<div id="layout-content"><div id="function.class-uses" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">class_uses</h1>
|
|
<p class="verinfo">(PHP 5 >= 5.4.0, PHP 7)</p><p class="refpurpose"><span class="refname">class_uses</span> — <span class="dc-title">
|
|
Return the traits used by the given class
|
|
</span></p>
|
|
|
|
</div>
|
|
<div class="refsect1 description" id="refsect1-function.class-uses-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>class_uses</strong></span>
|
|
( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$class</code></span>
|
|
[, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$autoload</code><span class="initializer"> = <strong><code>TRUE</code></strong></span></span>
|
|
] ) : <span class="type">array</span></div>
|
|
|
|
<p class="para rdfs-comment">
|
|
This function returns an array with the names of the traits that the
|
|
given <code class="parameter">class</code> uses. This does however not include
|
|
any traits used by a parent class.
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.class-uses-parameters">
|
|
<h3 class="title">参数</h3>
|
|
<p class="para">
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">class</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
An object (class instance) or a string (class name).
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">autoload</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
Whether to allow this function to load the class automatically through
|
|
the <span class="function"><a href="autoload.html" class="function">__autoload()</a></span> magic method.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.class-uses-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
An array on success, or <strong><code>FALSE</code></strong> on error.
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 examples" id="refsect1-function.class-uses-examples">
|
|
<h3 class="title">范例</h3>
|
|
<p class="para">
|
|
<div class="example" id="regexiterator.accept.example.basic">
|
|
<p><strong>Example #1 <span class="function"><strong>class_uses()</strong></span> example</strong></p>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br /><br /></span><span style="color: #007700">trait </span><span style="color: #0000BB">foo </span><span style="color: #007700">{ }<br />class </span><span style="color: #0000BB">bar </span><span style="color: #007700">{<br /> use </span><span style="color: #0000BB">foo</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">class_uses</span><span style="color: #007700">(new </span><span style="color: #0000BB">bar</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">class_uses</span><span style="color: #007700">(</span><span style="color: #DD0000">'bar'</span><span style="color: #007700">));<br /><br />function </span><span style="color: #0000BB">__autoload</span><span style="color: #007700">(</span><span style="color: #0000BB">$class_name</span><span style="color: #007700">) {<br /> require_once </span><span style="color: #0000BB">$class_name </span><span style="color: #007700">. </span><span style="color: #DD0000">'.php'</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">// use __autoload to load the 'not_loaded' class<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">class_uses</span><span style="color: #007700">(</span><span style="color: #DD0000">'not_loaded'</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
<div class="example-contents"><p>以上例程的输出类似于:</p></div>
|
|
<div class="example-contents screen">
|
|
<div class="cdata"><pre>
|
|
Array
|
|
(
|
|
[foo] => foo
|
|
)
|
|
|
|
Array
|
|
(
|
|
[foo] => foo
|
|
)
|
|
|
|
Array
|
|
(
|
|
[trait_of_not_loaded] => trait_of_not_loaded
|
|
)
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.class-uses-seealso">
|
|
<h3 class="title">参见</h3>
|
|
<p class="para">
|
|
<ul class="simplelist">
|
|
<li class="member"><span class="function"><a href="class_parents.html" class="function" rel="rdfs-seeAlso">class_parents()</a> - 返回指定类的父类。</span></li>
|
|
<li class="member"><span class="function"><a href="get_declared_traits.html" class="function" rel="rdfs-seeAlso">get_declared_traits()</a> - 返回所有已定义的 traits 的数组</span></li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
</div></div></div></body></html> |