uTools-Manuals/docs/php/property_exists.html
2019-04-28 19:00:34 +08:00

146 lines
8.3 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>检查对象或类是否具有该属性</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.property-exists" class="refentry">
<div class="refnamediv">
<h1 class="refname">property_exists</h1>
<p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7)</p><p class="refpurpose"><span class="refname">property_exists</span> &mdash; <span class="dc-title">检查对象或类是否具有该属性</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.property-exists-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>property_exists</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">string</span> <code class="parameter">$property</code></span>
) : <span class="type">bool</span></div>
<p class="para rdfs-comment">
本函数检查给出的 <code class="parameter">property</code> 是否存在于指定的类中(以及是否能在当前范围内访问)。
</p>
<blockquote class="note"><p><strong class="note">Note</strong>:
<p class="para">
As opposed with <span class="function"><a href="isset.html" class="function">isset()</a></span>,
<span class="function"><strong>property_exists()</strong></span> returns <strong><code>TRUE</code></strong> even if the property
has the value <strong><code>NULL</code></strong>.
</p>
</p></blockquote>
</div>
<div class="refsect1 parameters" id="refsect1-function.property-exists-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">class</code></dt>
<dd>
<p class="para">
字符串形式的类名或要检查的类的一个对象
</p>
</dd>
<dt>
<code class="parameter">property</code></dt>
<dd>
<p class="para">
属性的名字
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.property-exists-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
如果该属性存在则返回 <strong><code>TRUE</code></strong>,如果不存在则返回 <strong><code>FALSE</code></strong>,出错返回 <strong><code>NULL</code></strong>
</p>
</div>
<div class="refsect1 notes" id="refsect1-function.property-exists-notes">
<h3 class="title">注释</h3>
<blockquote class="note"><p><strong class="note">Note</strong>: <p class="para">如果此类不是已知类,使用此函数会使用任何已注册的
<a href="language.oop5.autoload.html" class="link">autoloader</a></p></p></blockquote>
<blockquote class="note"><p><strong class="note">Note</strong>:
<p class="para">
The <span class="function"><strong>property_exists()</strong></span> function cannot detect properties
that are magically accessible using the <a href="language.oop5.overloading.html#language.oop5.overloading.members" class="link"><em>__get</em></a>
magic method.
</p>
</p></blockquote>
</div>
<div class="refsect1 changelog" id="refsect1-function.property-exists-changelog">
<h3 class="title">更新日志</h3>
<p class="para">
<table class="doctable informaltable">
<thead>
<tr>
<th>版本</th>
<th>说明</th>
</tr>
</thead>
<tbody class="tbody">
<tr>
<td>5.3.0</td>
<td>
This function checks the existence of a property independent of
accessibility.
</td>
</tr>
</tbody>
</table>
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.property-exists-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-6153">
<p><strong>Example #1 A <span class="function"><strong>property_exists()</strong></span> example</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">myClass&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;</span><span style="color: #0000BB">$mine</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;</span><span style="color: #0000BB">$xpto</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;protected&nbsp;</span><span style="color: #0000BB">$test</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;function&nbsp;</span><span style="color: #0000BB">test</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">property_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'myClass'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'xpto'</span><span style="color: #007700">));&nbsp;</span><span style="color: #FF8000">//true<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">}<br />}<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">property_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'myClass'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'mine'</span><span style="color: #007700">));&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//true<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">property_exists</span><span style="color: #007700">(new&nbsp;</span><span style="color: #0000BB">myClass</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'mine'</span><span style="color: #007700">));&nbsp;</span><span style="color: #FF8000">//true<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">property_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'myClass'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'xpto'</span><span style="color: #007700">));&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//true,&nbsp;as&nbsp;of&nbsp;PHP&nbsp;5.3.0<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">property_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'myClass'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'bar'</span><span style="color: #007700">));&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//false<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">property_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'myClass'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'test'</span><span style="color: #007700">));&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//true,&nbsp;as&nbsp;of&nbsp;PHP&nbsp;5.3.0<br /></span><span style="color: #0000BB">myClass</span><span style="color: #007700">::</span><span style="color: #0000BB">test</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 seealso" id="refsect1-function.property-exists-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="method_exists.html" class="function" rel="rdfs-seeAlso">method_exists()</a> - 检查类的方法是否存在</span></li>
</ul>
</p>
</div>
</div></div></div></body></html>