-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Translate the /language/types/ section
- Loading branch information
Showing
22 changed files
with
6,195 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- EN-Revision: 117340b0d72bc8884290450ae8b89643528e0f58 Maintainer: sobak Status: ready --> | ||
<chapter xml:id="language.types" xmlns="http://docbook.org/ns/docbook"> | ||
<title>Typy</title> | ||
|
||
<sect1 xml:id="language.types.intro"> | ||
<title>Wprowadzenie</title> | ||
|
||
<para> | ||
Każde jedno wyrażenie w PHP ma jeden z następujących | ||
wbudowanych typów, zależnie od jego wartości: | ||
<itemizedlist> | ||
<listitem><simpara><type>null</type></simpara></listitem> | ||
<listitem><simpara><type>bool</type></simpara></listitem> | ||
<listitem><simpara><type>int</type></simpara></listitem> | ||
<listitem><simpara><type>float</type> (liczba zmiennoprzecinkowa)</simpara></listitem> | ||
<listitem><simpara><type>string</type></simpara></listitem> | ||
<listitem><simpara><type>array</type></simpara></listitem> | ||
<listitem><simpara><type>object</type></simpara></listitem> | ||
<listitem><simpara><type>callable</type></simpara></listitem> | ||
<listitem><simpara><type>resource</type></simpara></listitem> | ||
</itemizedlist> | ||
</para> | ||
|
||
<para> | ||
PHP jest językiem typowanym dynamicznie, co oznacza, że domyślnie nie ma | ||
potrzeby określania typu zmiennej, bo będzie on określony w | ||
trakcie wykonywania kodu. Jednakże jest możliwe statyczne otypowanie niektórych elementów | ||
języka używając | ||
<link linkend="language.types.declarations">deklaracji typu</link>. | ||
Różne typy wspierane przez system typowania PHP można znaleźć na | ||
stronie o <link linkend="language.types.type-system">systemie typowania</link>. | ||
</para> | ||
|
||
<para> | ||
Typy określają rodzaj operacji, który można na nich wykonać. | ||
Jednak jeśli wyrażenie lub zmienna są użyte w operacji, która | ||
nie jest wspierana przez ich typ, PHP spróbuje wykonać | ||
<link linkend="language.types.type-juggling">dopasowanie typów</link> | ||
wartości tak, aby uzyskać obsługujący daną operację. | ||
Ten proces zależy od kontekstu, w którym użyta jest wartość. | ||
Aby dowiedzieć się więcej na ten temat, możesz przeczytać sekcję | ||
o <link linkend="language.types.type-juggling">Żonglowaniu typami</link>. | ||
</para> | ||
|
||
<tip> | ||
<simpara> | ||
Przydatne mogą być też <link linkend="types.comparisons">tablice porównań typów</link>, | ||
które zawierają najróżniejsze przykłady porównań między wartościami | ||
różnych typów. | ||
</simpara> | ||
</tip> | ||
|
||
<note> | ||
<simpara> | ||
Można wymusić aby wyrażenie było skonwertowane na określony typ używając | ||
<link linkend="language.types.typecasting">rzutowania typu</link>. | ||
Zmienna może być też zrzutowana poprzez użycie na niej | ||
funkcji <function>settype</function>. | ||
</simpara> | ||
</note> | ||
|
||
<para> | ||
Aby sprawdzić wartość i typ | ||
<link linkend="language.expressions">wyrażenia</link> | ||
użyj funkcji <function>var_dump</function>. | ||
Aby pobrać tylko typ | ||
<link linkend="language.expressions">wyrażenia</link> | ||
użyj funkcji <function>get_debug_type</function>. | ||
Jednak jeśli chcesz sprawdzić, czy wyrażenie ma określony typ, to skorzystaj | ||
z jednej z funkcji <literal>is_<replaceable>typ</replaceable></literal>. | ||
|
||
<informalexample> | ||
<programlisting role="php"> | ||
<![CDATA[ | ||
<?php | ||
$a_bool = true; // wartość logiczna | ||
$a_str = "foo"; // ciąg znaków | ||
$a_str2 = 'foo'; // ciąg znaków | ||
$an_int = 12; // liczba całkowita | ||
echo get_debug_type($a_bool), "\n"; | ||
echo get_debug_type($a_str), "\n"; | ||
// Jeśli jest liczbą całkowitą, to powiększ o cztery | ||
if (is_int($an_int)) { | ||
$an_int += 4; | ||
} | ||
var_dump($an_int); | ||
// Jeśli $a_bool jest ciągiem znaków, to go wyświetl | ||
if (is_string($a_bool)) { | ||
echo "String: $a_bool"; | ||
} | ||
?> | ||
]]> | ||
</programlisting> | ||
&example.outputs.8; | ||
<screen> | ||
<![CDATA[ | ||
bool | ||
string | ||
int(16) | ||
]]> | ||
</screen> | ||
</informalexample> | ||
</para> | ||
<note> | ||
<simpara> | ||
Przez PHP 8.0.0, gdzie funkcja <function>get_debug_type</function> nie jest | ||
dostępna, można skorzystać z funkcji <function>gettype</function>. | ||
Nie używa ona jednak podstawowych nazw typów. | ||
</simpara> | ||
</note> | ||
</sect1> | ||
|
||
&language.types.type-system; | ||
&language.types.null; | ||
&language.types.boolean; | ||
&language.types.integer; | ||
&language.types.float; | ||
&language.types.string; | ||
&language.types.numeric-strings; | ||
&language.types.array; | ||
&language.types.object; | ||
&language.types.enumerations; | ||
&language.types.resource; | ||
&language.types.callable; | ||
&language.types.mixed; | ||
&language.types.void; | ||
&language.types.never; | ||
&language.types.relative-class-types; | ||
&language.types.singleton; | ||
&language.types.iterable; | ||
&language.types.declarations; | ||
&language.types.type-juggling; | ||
|
||
</chapter> | ||
<!-- 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 | ||
--> |
Oops, something went wrong.