1
0
mirror of https://github.com/php/doc-zh.git synced 2026-03-23 22:52:08 +01:00
Files
archived-doc-zh/reference/classobj/functions/property-exists.xml
2024-01-29 23:56:20 +08:00

132 lines
3.3 KiB
XML
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: a4fb7f59310a598b8cb8ca1daa47e557f32ae66e Maintainer: HonestQiao Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<refentry xml:id="function.property-exists" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>property_exists</refname>
<refpurpose>
检查对象或类是否具有该属性
</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>bool</type><methodname>property_exists</methodname>
<methodparam><type class="union"><type>object</type><type>string</type></type><parameter>object_or_class</parameter></methodparam>
<methodparam><type>string</type><parameter>property</parameter></methodparam>
</methodsynopsis>
<para>
本函数检查给出的 <parameter>property</parameter> 是否存在于指定的类中。
</para>
<note>
<para>
<function>isset</function> 的区别是即使属性的值为 &null;<function>property_exists</function> 也会返回 &true;
</para>
</note>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>object_or_class</parameter></term>
<listitem>
<para>
需要检查的类名或者类的对象
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>property</parameter></term>
<listitem>
<para>
属性的名称
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
如果属性存在则返回 &true;,不存在则返回 &false;
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>property_exists</function> 示例</title>
<programlisting role="php">
<![CDATA[
<?php
class myClass {
public $mine;
private $xpto;
static protected $test;
static function test() {
var_dump(property_exists('myClass', 'xpto')); //true
}
}
var_dump(property_exists('myClass', 'mine')); //true
var_dump(property_exists(new myClass, 'mine')); //true
var_dump(property_exists('myClass', 'xpto')); //true
var_dump(property_exists('myClass', 'bar')); //false
var_dump(property_exists('myClass', 'test')); //true
myClass::test();
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
&note.uses-autoload;
<note>
<para>
<function>property_exists</function> 函数不能检查通过
<link linkend="language.oop5.overloading.members"><literal>__get</literal></link>
魔术方法访问的属性。
</para>
</note>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>method_exists</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->