php-doc-en/reference/classobj/functions/is-a.xml
Philip Olson ca0e422a27 Mention (with an example) that is_a() is deprecated in PHP 5 in favor of the
instanceof operator.  This deals with bug #27503


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@159560 c90b9560-bf6c-de11-be94-00142212c4b1
2004-05-24 21:53:23 +00:00

93 lines
2.4 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.7 $ -->
<!-- splitted from ./en/functions/classobj.xml, last change in rev 1.33 -->
<refentry id="function.is-a">
<refnamediv>
<refname>is_a</refname>
<refpurpose>
Returns &true; if the object is of this class or has this class as
one of its parents
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>bool</type><methodname>is_a</methodname>
<methodparam><type>object</type><parameter>object</parameter></methodparam>
<methodparam><type>string</type><parameter>class_name</parameter></methodparam>
</methodsynopsis>
<para>
This function returns &true; if the object is of this class or
has this class as one of its parents, &false; otherwise.
</para>
<para>
<example>
<title><function>is_a</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
// define a class
class WidgetFactory
{
var $oink = 'moo';
}
// create a new object
$WF = new WidgetFactory();
if (is_a($WF, 'WidgetFactory')) {
echo "yes, \$WF is still a WidgetFactory\n";
}
?>
]]>
</programlisting>
</example>
</para>
<para>
The <function>is_a</function> function is deprecated as of PHP 5 in
favor of the <link linkend="language.operators.type">instanceof</link>
type operator. In the above example we could use the following in
PHP 5:
</para>
<para>
<example>
<title>Using the <emphasis>instanceof</emphasis> operator in PHP 5</title>
<programlisting role="php">
<![CDATA[
<?php
if ($WF instanceof WidgetFactory) {
echo 'Yes, $WF is a WidgetFactory';
}
?>
]]>
</programlisting>
</example>
</para>
<simpara>
See also <function>get_class</function>,
<function>get_parent_class</function>, and
<function>is_subclass_of</function>.
</simpara>
</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:"../../../../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
-->