php-doc-en/reference/classobj/functions/get-class.xml

101 lines
2.3 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.9 $ -->
<refentry id="function.get-class">
<refnamediv>
<refname>get_class</refname>
<refpurpose>Returns the name of the class of an object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>string</type><methodname>get_class</methodname>
<methodparam choice="opt"><type>object</type><parameter>obj</parameter></methodparam>
</methodsynopsis>
<para>
This function returns the name of the class of which the
object <parameter>obj</parameter> is an instance. Returns
&false; if <parameter>obj</parameter> is not an object.
</para>
<note>
<simpara>
A class defined in a PHP extension is returned in its original notation.
In PHP 4 <function>get_class</function> returns a user defined class
name in lowercase, but in PHP 5 it will return the class name in it's
original notation too, just like class names from PHP extensions.
</simpara>
</note>
<note>
<para>
Since PHP 5, <parameter>obj</parameter> is optional if called from the
object's method.
</para>
</note>
<para>
<example>
<title>Using <function>get_class</function></title>
<programlisting role="php">
<![CDATA[
<?php
class foo {
function foo()
{
// implements some logic
}
function name()
{
echo "My name is " , get_class($this) , "\n";
}
}
// create an object
$bar = new foo();
// external call
echo "Its name is " , get_class($bar) , "\n";
// internal call
$bar->name();
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Its name is foo
My name is foo
]]>
</screen>
</example>
</para>
<para>
See also <function>get_parent_class</function>,
<function>gettype</function>, and
<function>is_subclass_of</function>.
</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:"../../../../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
-->