mirror of
https://github.com/php/doc-pl.git
synced 2026-03-25 07:32:14 +01:00
236 lines
5.7 KiB
XML
236 lines
5.7 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: 4f36c26a72c40b16e955c3c1c88041910932d0bf Maintainer: sobak Status: ready -->
|
|
<!-- $Revision$ -->
|
|
<!-- CREDITS: dombal -->
|
|
<refentry xml:id="function.get-class" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>get_class</refname>
|
|
<refpurpose>Zwraca nazwę klasy danego obiektu</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>string</type><methodname>get_class</methodname>
|
|
<methodparam choice="opt"><type>object</type><parameter>object</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Zwraca nazwę klasy reprezentującej <parameter>object</parameter>.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>object</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Sprawdzany obiekt.
|
|
</para>
|
|
<note>
|
|
<simpara>
|
|
Jawne przekazanie &null; jako <parameter>object</parameter> jest niedozwolone
|
|
od wersji PHP 7.2.0 i powoduje wygenerowanie ostrzeżenia (<constant>E_WARNING</constant>).
|
|
Od PHP 8.0.0 w przypadku użycia &null; rzucany jest <classname>TypeError</classname>.
|
|
</simpara>
|
|
</note>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Zwraca nazwę klasy, której instancją jest <parameter>obiekt</parameter>.
|
|
</para>
|
|
<para>
|
|
Jeżeli <parameter>obiekt</parameter> jest instancją klasy, która istnieje w przestrzeni nazw,
|
|
zwracana jest kwalifikowana nazwa tej klasy.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="errors">
|
|
&reftitle.errors;
|
|
<para>
|
|
Jeżeli <function>get_class</function> jest wykonywana na czymkolwiek innym niż
|
|
obiekcie, rzucany jest <classname>TypeError</classname>. Przed PHP 8.0.0
|
|
generowane było ostrzeżenie (<constant>E_WARNING</constant>).
|
|
</para>
|
|
<para>
|
|
Jeżeli <function>get_class</function> zostanie wywołane bez argumentów spoza klasy,
|
|
rzucony zostanie <classname>Error</classname>. Przed PHP 8.0.0
|
|
generowane było ostrzeżenie (<constant>E_WARNING</constant>).
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<para>
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>8.3.0</entry>
|
|
<entry>
|
|
Wywołanie <function>get_class</function> bez argumentu powoduje teraz wygenerowanie błędu
|
|
<constant>E_DEPRECATED</constant>;
|
|
wcześniej wywołanie tej funkcji bez parametru z wewnątrz klasy zwracało nazwę tej klasy..
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>8.0.0</entry>
|
|
<entry>
|
|
Wywołanie tej funkcji spoza klasy bez żadnych argumentów spowoduje
|
|
teraz rzucenie wyjątku <classname>Error</classname>.
|
|
Wcześniej generowane było ostrzeżenie (<constant>E_WARNING</constant>)
|
|
a funkcja zwracała &false;.
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>7.2.0</entry>
|
|
<entry>
|
|
&null; nie jest już domyślną wartością parametru <parameter>obiekt</parameter>,
|
|
i nie może być do niej przekazane.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Przykład użycia <function>get_class</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
class foo {
|
|
function nazwa()
|
|
{
|
|
echo "Nazywam się " , get_class($this) , "\n";
|
|
}
|
|
}
|
|
|
|
// tworzymy obiekt
|
|
$bar = new foo();
|
|
|
|
// zewnętrzne wołanie
|
|
echo "Jego nazwa to " , get_class($bar) , "\n";
|
|
|
|
// wewnętrzne wołanie
|
|
$bar->nazwa();
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
Jego nazwa to foo
|
|
Nazywam się foo
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
<example>
|
|
<title>Użycie <function>get_class</function> w klasach specjalnych</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
abstract class bar {
|
|
public function __construct()
|
|
{
|
|
var_dump(get_class($this));
|
|
var_dump(get_class());
|
|
}
|
|
}
|
|
|
|
class foo extends bar {
|
|
}
|
|
|
|
new foo;
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
string(3) "foo"
|
|
string(3) "bar"
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
<example>
|
|
<title>Użycie <function>get_class</function> z klasami w przestrzeniach nazw</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
namespace Foo\Bar;
|
|
|
|
class Baz {
|
|
public function __construct()
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
$baz = new \Foo\Bar\Baz;
|
|
|
|
var_dump(get_class($baz));
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
string(11) "Foo\Bar\Baz"
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>get_called_class</function></member>
|
|
<member><function>get_parent_class</function></member>
|
|
<member><function>gettype</function></member>
|
|
<member><function>get_debug_type</function></member>
|
|
<member><function>is_subclass_of</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
|
|
-->
|