cvs: phpdoc /pl Translators bookinfo.xml language-snippets.ent /pl/functions mysql.xml /pl/language constants.xml oop.xml

From: Date: Tue, 30 Oct 2001 12:31:03 +0000
Subject: cvs: phpdoc /pl Translators bookinfo.xml language-snippets.ent /pl/functions mysql.xml /pl/language constants.xml oop.xml
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969338325@lists.php.net to get a copy of this message
leszek Tue Oct 30 07:31:03 2001 EDT Modified files: /phpdoc/pl Translators bookinfo.xml language-snippets.ent /phpdoc/pl/functions mysql.xml /phpdoc/pl/language constants.xml oop.xml Log: Update: new chapter, updated some other chapters

Index: phpdoc/pl/Translators diff -u phpdoc/pl/Translators:1.2 phpdoc/pl/Translators:1.3 --- phpdoc/pl/Translators:1.2 Tue Oct 23 12:12:40 2001 +++ phpdoc/pl/Translators Tue Oct 30 07:31:01 2001 @@ -2,6 +2,7 @@ Polish PHP Documentation Translation Team Member List (PPDTTML? :) DomBal Marcin D±browski dombal@rpg.pl +kurtz Wojciech Jukowski wojtek@jukowski.com Leon Leszek Krupiñski leszek@php.net Yagood Pawe³ Paprota yagood@hoga.pl slawek S³awomir Pucia slawek@php.net @@ -58,7 +59,7 @@ aspell.xml bc.xml bzip2.xml -calendar.xml +calendar.xml kurtz started 1.15 ccvs.xml classobj.xml com.xml @@ -67,13 +68,13 @@ curl.xml cybercash.xml cybermut.xml -datetime.xml +datetime.xml kurtz started 1.49 dba.xml dbase.xml dbm.xml dbplus.xml dbx.xml -dir.xml +dir.xml kurtz started 1.21 domxml.xml errorfunc.xml exec.xml @@ -85,7 +86,7 @@ funchand.xml gettext.xml gmp.xml -http.xml Qrak done ?.?? +http.xml Qrak done 1.28 hw.xml ibase.xml icap.xml @@ -99,7 +100,7 @@ java.xml ldap.xml mail.xml Qrak done 1.29 -math.xml Qrak started ?.?? +math.xml Qrak started 1.55 mbstring.xml mcal.xml mcrypt.xml @@ -131,11 +132,11 @@ satellite.xml sem.xml sesam.xml -session.xml +session.xml leon started 1.53 shmop.xml snmp.xml sockets.xml -strings.xml +strings.xml kurtz started 1.117 swf.xml sybase.xml uodbc.xml @@ -153,7 +154,7 @@ control-structures.xml expressions.xml Leon done 1.14 functions.xml Leon done 1.17 -oop.xml Leon started 1.28 +oop.xml Leon done 1.28 operators.xml Qrak started 1.27 references.xml types.xml Index: phpdoc/pl/bookinfo.xml diff -u phpdoc/pl/bookinfo.xml:1.2 phpdoc/pl/bookinfo.xml:1.3 --- phpdoc/pl/bookinfo.xml:1.2 Tue Oct 23 12:15:00 2001 +++ phpdoc/pl/bookinfo.xml Tue Oct 30 07:31:01 2001 @@ -1,5 +1,5 @@ <?xml encoding="iso-8859-2"?> -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> <bookinfo id="bookinfo"> <authorgroup id="authors"> @@ -62,9 +62,6 @@ </collab> <collab> <collabname>Marcin D±browski</collabname> - </collab> - <collab> - <collabname>Pawe³ Paprota</collabname> </collab> </authorgroup> Index: phpdoc/pl/language-snippets.ent diff -u phpdoc/pl/language-snippets.ent:1.1 phpdoc/pl/language-snippets.ent:1.2 --- phpdoc/pl/language-snippets.ent:1.1 Tue Oct 23 07:19:35 2001 +++ phpdoc/pl/language-snippets.ent Tue Oct 30 07:31:02 2001 @@ -1,7 +1,7 @@ -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <!ENTITY warn.experimental '<warning><simpara>Ten modu³ jest w stadium <emphasis>EKSPERYMENTALNYM</emphasis>. Oznacza to, ¿e zachowanie tych funkcji, ich nazwy, w zasadzie WSZYSTKO udokumentowane tutaj mo¿e zostaæ zmienione w przysz³ych wersjach PHP BEZ WCZE¦NIEJSZEGO UPRZEDZENIA. U¿ywaj tego modu³u na w³asne ryzyko.</simpara></warning>'> -<!ENTITY warn.experimental.func '<warning><simpara>Ta funkcja jest w stadium <emphasis>EKSPERYMENTALNYM</emphasis>. Oznacza to, ¿e zachowanie teh funkcji, jej nazwa, w zasadzie wszystko udokumentowane tutaj mo¿e zostaæ zmienione w przysz³ych wersjach PHP BEZ WCZE¦NIEJSZEGO UPRZEDZENIA. U¿ywaj tej funkcji na w³asne ryzyko.</simpara></warning>'> +<!ENTITY warn.experimental.func '<warning><simpara>Ta funkcja jest w stadium <emphasis>EKSPERYMENTALNYM</emphasis>. Oznacza to, ¿e zachowanie funkcji, jej nazwa, w zasadzie wszystko udokumentowane tutaj mo¿e zostaæ zmienione w przysz³ych wersjach PHP BEZ WCZE¦NIEJSZEGO UPRZEDZENIA. U¿ywaj tej funkcji na w³asne ryzyko.</simpara></warning>'> <!ENTITY tip.ob-capture '<tip><simpara>Ze wszystkim, co wysy³a dane bezpo¶rednio do przegl±darki, mo¿esz u¿ywaæ <link linkend="ref.outcontrol">funkcji kontroli wyj¶cia</link> aby przej±æ wyj¶cie tej funkcji i zapisaæ je - na przyk³ad - w zmiennej tekstowej.</simpara></tip>'> Index: phpdoc/pl/functions/mysql.xml diff -u phpdoc/pl/functions/mysql.xml:1.1 phpdoc/pl/functions/mysql.xml:1.2 --- phpdoc/pl/functions/mysql.xml:1.1 Tue Oct 23 07:19:36 2001 +++ phpdoc/pl/functions/mysql.xml Tue Oct 30 07:31:02 2001 @@ -1,5 +1,5 @@ <?xml encoding="iso-8859-2"?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <reference id="ref.mysql"> <title>Funkcje MySQL</title> <titleabbrev>MySQL</titleabbrev> @@ -1760,8 +1760,8 @@ </para> </note> <para> - <function>mysql_query</function> zwraca &true; (nie-zero) lub &false; - informuj±c czy zapytanie zakoñczy³o siê sukcesem lub te¿ nie. + <function>mysql_query</function> zwraca &true; lub &false; + informuj±c czy zapytanie zakoñczy³o siê sukcesem czy te¿ nie. Zwrócona warto¶æ &true; oznacza, ¿e zapytanie by³o prawid³owe i mo¿e byæ wykonane przez serwer. Nie mówi natomiast nic o liczbie przetworzonych lub zwróconych wierszy. Jest równie¿ mo¿liwe, ¿e Index: phpdoc/pl/language/constants.xml diff -u phpdoc/pl/language/constants.xml:1.1 phpdoc/pl/language/constants.xml:1.2 --- phpdoc/pl/language/constants.xml:1.1 Tue Oct 23 07:19:37 2001 +++ phpdoc/pl/language/constants.xml Tue Oct 30 07:31:02 2001 @@ -1,244 +1,244 @@ -<?xml encoding="iso-8859-1"?> -<!-- $Revision: 1.1 $ --> +<?xml encoding="iso-8859-2"?> +<!-- $Revision: 1.2 $ --> <chapter id="language.constants"> - <title>Constants</title> + <title>Sta³e</title> <simpara> - A constant is a identifier (name) for a simple value. As the name - suggests, that value cannot change during the execution of the script - (the magic constants <constant>__FILE__</constant> and - <constant>__LINE__</constant> are the only exception). A constant - is case-sensitive by default. By convention constants are always - uppercase. + Sta³a jest identyfikatorem (nazw±) dla prostej warto¶ci. Jak sama + nazwa wskazuje, warto¶æ ta nie mo¿e siê zmieniaæ podczas dzia³ania + skryptu (poza wyj±tkami: <constant>__FILE__</constant> + i <constant>__LINE__</constant>). Domy¶lnie, przy sta³ych + uwzglêdniana jest wielko¶æ liter. Przyjêto, ¿e sta³e s± pisane du¿ymi + literami. </simpara> <para> - The name of a constant follows the same rules as any label in PHP. A - valid constant name starts with a letter or underscore, followed - by any number of letters, numbers, or underscores. As a regular - expression, it would be expressed thus: + Nazwa sta³ej podlega takim samym zasadom jak ka¿da inna w PHP. + Prawid³owa nazwa sta³ej rozpoczyna siê liter±, znakiem podkre¶lenia + ("_"), nastêpnie mog± wystêpowaæ litery, cyfry lub znaki podkre¶lenia. + Dobrze reprezentuje to takie wyra¿enie regularne: <literal>[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*</literal> <!-- TODO: Example of valid & invalid constant names --> </para> - + <note> <simpara> - For our purposes here, a letter is a-z, A-Z, and the ASCII - characters from 127 through 255 (0x7f-0xff). + Na nasze potrzeby, litery to a-z, A-Z, oraz znaki ASCII + od 127 do 255 (0x7f-0xff). </simpara> </note> <simpara> - The scope of a constant is global. + Zakres sta³ej jest globalny. </simpara> <sect1 id="language.constants.syntax"> - <title>Syntax</title> + <title>Sk³adnia</title> <simpara> - You can define a constant by using the - <function>define</function>-function. Once a constant is defined, - it can never be changed or undefined. + Mo¿esz definiowaæ sta³± u¿ywaj±c funkcji <function>define</function>. + Kiedy sta³a zostanie zdefiniowana, nie mo¿e byæ ju¿ zmieniona albo + undefined. </simpara> <simpara> - Only scalar data (<type>boolean</type>, <type>integer</type>, - <type>double</type> and <type>string</type>) can be contained - in constants. + Tylko skalarne typy danych + (<type>boolean</type>, <type>integer</type>, <type>double</type> + i <type>string</type>) mog± byæ zawarte w sta³ych. </simpara> <simpara> - You can get the value of a constant by simply specifying its name. - Unlike with variables, you should <emphasis>not</emphasis> prepend - a constant with a <literal>$</literal>. - You can also use the function <function>constant</function>, to - read a constant's value, if you are to obtain the constant's name - dynamically. - Use <function>get_defined_constants</function> to get a list of - all defined constants. + Mo¿esz u¿yæ warto¶ci sta³ej poprzez zwyk³e u¿ycie jej nazwy. + Inaczej ni¿ przy zmiennych, w sta³ych <emphasis>NIE</emphasis> + powiniene¶ prepend sta³ej znakiem <literal>$</literal>. + Mo¿esz tak¿e u¿yæ funkcji <function>constant</function>, aby + odczytaæ warto¶æ sta³ej, której nazwa jest przekazywana dynamicznie. + U¿yj funkcji <function>get_defined_constants</function> aby otrzymaæ + listê zdefiniowanych sta³ych. </simpara> <note> <simpara> - Constants and (global) variables are in a different namespace. - This implies that for example &true; and - <varname>$TRUE</varname> are generally different. + Sta³e i globlane zmienne s± pisane inaczej, a to oznacza, ¿e np. + &true; i <varname>$TRUE</varname> s± ró¿ne. </simpara> </note> <simpara> - If you use an undefined constant, PHP assumes that you mean - the name of the constant itself. A - <link linkend="features.error-handling">notice</link> will be issued - when this happens. Use the <function>defined</function>-function if - you want to know if a constant is set. + Je¶li u¿yjesz niezdefiniowanej sta³ej, PHP przyjmuje, ¿e chcesz u¿yæ + nazwy sta³ej samej w sobie. Zostanie wtedy wys³ane + <link linkend="features.error-handling">ostrze¿enie</link>. + U¿yj funkcji <function>defined</function> je¶li chcesz siê dowiedzieæ + czy sta³a jest zdefiniowana. </simpara> <para> - This are the differences with variables: + Ró¿nice pomiêdzy sta³ymi, a zmiennymi: <itemizedlist> <listitem> <simpara> - Constants do not have a dollar sign (<literal>$</literal>) before them; + Sta³e nie maj± znaku dolara (<literal>$</literal>) przed nazw±; </simpara> </listitem> <listitem> <simpara> - Constants may be defined and accessed anywhere without regard to variable - scoping rules; + Sta³e mog± byæ definiowane oraz u¿ywane wszêdzie bez zwa¿ania na + zasady dotycz±ce zakresu ich dostêpno¶ci; </simpara> </listitem> <listitem> <simpara> - Constants may not be redefined or undefined once they have - been set; and + Sta³e nie mog± byæ redefiniowane lub undefined po tym jak raz zosta³y + zdefiniowane; i </simpara> </listitem> <listitem> <simpara> - Constants may only evaluate to scalar values. + Sta³e mog± zawieraæ tylko warto¶ci skalarne. </simpara> </listitem> </itemizedlist> </para> - + <para> <example> - <title>Defining Constants</title> + <title>Definiowanie sta³ych</title> <programlisting> &lt;?php -define("CONSTANT", "Hello world."); -echo CONSTANT; // outputs "Hello world." -echo Constant; // outputs "Constant" and issues a notice. +define("STALA", "Hello world!"); +echo STALA; // wy¶wietli "Hello world!" +echo Stala; // wy¶wietli "Stala" i zg³osi ostrze¿enie ?&gt; </programlisting> </example> </para> - + </sect1> - + <sect1 id="language.constants.predefined"> - <title>Predefined constants</title> + <title>Predefiniowane sta³e</title> <para> - The predefined constants (always available) are: + Predefiniowanymi sta³ymi (zawsze dostêpnymi) s±: <variablelist> <varlistentry> - <term>__FILE__ (case-insensitive)</term> + <term>__FILE__ (niewa¿na wielko¶æ liter)</term> <listitem> <simpara> - The name of the script file presently being parsed. If used - within a file which has been included or required, then the - name of the included file is given, and not the name of the - parent file. + Nazwa pliku ze skryptem PHP, który jest aktualnie parsowany + (przetwarzany); sta³a u¿yta w pliku, który zosta³, który zosta³ + w³±czony (include) lub jest wymagany (require), zwraca nazwê + tego w³a¶nie pliku, a nie nazwê pliku g³ównego. </simpara> </listitem> </varlistentry> - + <varlistentry> - <term>__LINE__ (case-insensitive)</term> + <term>__LINE__ (niewa¿na wielko¶æ liter)</term> <listitem> <simpara> - The number of the line within the current script file which is - being parsed. If used within a file which has been included or - required, then the position within the included file is given. + Numer linii w pliku, który jest aktualnie parsowany (przetwarzany). + Sta³a u¿yta w pliku w³±czonym (include) zwraca pozycjê w tym pliku. </simpara> </listitem> </varlistentry> - + <varlistentry> <term>PHP_VERSION</term> <listitem> <simpara> - The string representation of the version of the PHP parser - presently in use; e.g. '4.0.7-dev'. + £añcuch reprezentuj±cy aktualnie u¿ywan± wersjê parsera PHP, np. + '4.0.7-dev'. </simpara> </listitem> </varlistentry> - + <varlistentry> <term>PHP_OS</term> <listitem> <simpara> - The name of the operating system on which the PHP parser is - executing;. Possible values may be : + Nazwa systemu operacyjnego, na którym uruchomiony jest parser + PHP. Mo¿liwe warto¶ci to: "AIX", "Darwin" (MacOS), "Linux", "SunOS", "WIN32", "WINNT". - Note: other values may be available too. + Uwaga: inne warto¶ci równie¿ mog± byæ dostêpne. </simpara> </listitem> </varlistentry> - + <varlistentry> - <term>&true; (case-insensitive)</term> + <term>&true; (niewa¿na wielko¶æ liter)</term> <listitem> <simpara> - A &true; value (see the <type>boolean</type> type). + Warto¶æ &true; (zobacz: typ <type>boolean</type>). </simpara> </listitem> </varlistentry> - + <varlistentry> - <term>&false; (case-insensitive)</term> + <term>&false; (niewa¿na wielko¶æ liter)</term> <listitem> <simpara> - A &false; value (see the <type>boolean</type> type). + Warto¶æ &false; (zobacz: typ<type>boolean</type>). </simpara> </listitem> </varlistentry> - + <varlistentry> - <term>&null; (case-insensitive)</term> + <term>&null; (niewa¿na wielko¶æ liter)</term> <listitem> <simpara> - A &null; value (see the <type>null</type> type). + Warto¶æ &null; (zobacz: typ <type>null</type>). </simpara> </listitem> </varlistentry> - + <varlistentry> <term>E_ERROR</term> <listitem> <simpara> - Denotes an error other than a parsing error from which - recovery is not possible. + Oznacza b³±d inny ni¿ b³±d przy parsowaniu (przetwarzaniu), + którego naprawienie nie jest mo¿liwe. </simpara> </listitem> </varlistentry> - + <varlistentry> <term>E_WARNING</term> <listitem> <simpara> - Denotes a condition where PHP knows something is wrong, but - will continue anyway; these can be caught by the script - itself. An example would be an invalid regexp in + Oznacza stan, w którym PHP "wie", ¿e co¶ jest ¼le, ale + kontynuuje dzia³anie; b³êdy takie mog± byæ przechwycone przez sam + skrypt. + Przyk³adem mo¿e byæ nieprawid³owe wyra¿enie regularne w funkcji <function>ereg</function>. </simpara> </listitem> </varlistentry> - + <varlistentry> <term>E_PARSE</term> <listitem> <simpara> - The parser choked on invalid syntax in the script - file. Recovery is not possible. + Parser stan±³ przy nieprawid³owej sk³adni w skrypcie. Naprawa + b³êdu i kontynuacja nie jest mo¿liwa. </simpara> </listitem> </varlistentry> - + <varlistentry> <term>E_NOTICE</term> <listitem> <simpara> - Something happened which may or may not be an error. Execution - continues. Examples include using an unquoted string as an array - index, or accessing a variable which has not been set. + Zdarzy³o siê co¶ co mo¿e acz nie musi byæ b³êdem. PHP kontynuuje + dzia³anie. Przyk³adem mo¿e byæ u¿ywanie niepodanego ³añcucha jako + indeksu w tablicy albo ¿adanie dostêpu do niezadeklarowanej + zmiennej. </simpara> </listitem> </varlistentry> - + <varlistentry> <term>E_ALL</term> <listitem> <simpara> - All of the E_* constants rolled into one. If used with - <function>error_reporting</function>, will cause any and all - problems noticed by PHP to be reported. + Wszystkie sta³e E_* w jednej. Je¶li sta³a ta zostanie u¿yta z + funkcj± <function>error_reporting</function>, spowoduje to, ¿e + jakiekolwiek problemy zauwa¿one przez PHP bêd± zg³aszane przez + funkcjê. </simpara> </listitem> </varlistentry> @@ -247,28 +247,28 @@ </para> <para> - The <literal>E_*</literal> constants are typically used with the - <function>error_reporting</function> function for setting the - error reporting level. See all these constants at - <link linkend="features.error-handling">Error handling</link>. + Sta³e <literal>E_*</literal> s± zwykle u¿ywane z funkcj± + <function>error_reporting</function> aby ustawiæ poziom zg³aszania + b³êdów. Zobacz wszystkie takie sta³e w rozdziale + <link linkend="features.error-handling">Obs³uga b³êdów</link>. <example> - <title>Using __FILE__ and __LINE__</title> + <title>U¿ywanie __FILE__ i __LINE__</title> <programlisting> &lt;?php -function report_error($file, $line, $message) +function report_error($plik, $linia, $komunikat) { - echo "An error occured in $file on line $line: $message."; + echo "Wyst±pi³ b³±d w $plik w linii $linia: $message."; } -report_error(__FILE__, __LINE__, "Something went wrong!"); +report_error(__FILE__, __LINE__, "Co¶ posz³o ¼le!"); ?&gt; </programlisting> </example> </para> </sect1> </chapter> - + <!-- Keep this comment at the end of the file Local variables: mode: sgml Index: phpdoc/pl/language/oop.xml diff -u phpdoc/pl/language/oop.xml:1.1 phpdoc/pl/language/oop.xml:1.2 --- phpdoc/pl/language/oop.xml:1.1 Tue Oct 23 07:19:38 2001 +++ phpdoc/pl/language/oop.xml Tue Oct 30 07:31:02 2001 @@ -1,5 +1,5 @@ <?xml encoding="iso-8859-2"?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <chapter id="language.oop"> <title>Klasy i Obiekty</title> @@ -108,13 +108,11 @@ </programlisting> </informalexample> </note> -<!-- ??? --> <para> - Classes are types, that is, they are blueprints for actual - variables. You have to create a variable of the desired type with - the <literal>new</literal> operator. + Klasy s± typami, które s± w zasadzie tylko schematami dla w³a¶ciwych + zmiennych. Zmienne po¿±danego typu musisz stworzyæ korzystaj±c z operatora + <literal>new</literal>. </para> -<!-- ??? --> <informalexample> <programlisting role="php"> @@ -134,50 +132,45 @@ </para> <para> - Both, $cart and $another_cart, have functions add_item(), - remove_item() and a variable items. These are distinct - functions and variables. You can think of the objects as - something similar to directories in a filesystem. In a - filesystem you can have two different files README.TXT, as - long as they are in different directories. Just like with - directories where you'll have to type the full pathname in - order to reach each file from the toplevel directory, you - have to specify the complete name of the function you want - to call: In PHP terms, the toplevel directory would be the - global namespace, and the pathname separator would be -&gt;. - Thus, the names $cart-&gt;items and $another_cart-&gt;items - name two different variables. Note that the variable is - named $cart-&gt;items, not $cart-&gt;$items, that is, a - variable name in PHP has only a single dollar sign. + I $koszyk i $inny_koszyk maj± funkcje dodaj_produkt(), usun_produkt() i + zmienne. S± to osobne funkcje i zmienne. Obiekty mog± byæ postrzegane jako + katalogi w systemie plików. W systemie plików mo¿esz mieæ dwa ró¿ne pliki + README.TXT, ale tylko je¶li istniej± w osobnych katalogach. Aby odczytaæ + plik, bêd±c w g³ównym katalogu, musisz podaæ pe³n± ¶cie¿kê do tego pliku. + Tak samo jest przy obiektach: musisz podaæ pe³n± nazwê funkcji, z której + chcesz skorzystaæ. W terminologii PHP katalogiem g³ównym bêdzie globalna + przestrzeñ nazw a separatorem ¶cie¿ki bêdzie -&gt;. W zwi±zku z tym nazwy + $koszyk i $inny_koszyk zawieraj± zupe³nie inne zmienne. Zauwa¿, ¿e zmienna + nazywa siê $koszyk-&gt;artykuly, a nie $koszyk-&gt;$artykuly, poniewa¿ + nazwa zmiennej mo¿e zawieraæ tylko jeden znak dolara. </para> <informalexample> <programlisting role="php"> -// correct, single $ -$cart->items = array("10" => 1); +// poprawnie, jeden $ +$koszyk->artykuly = array("10" => 1); -// invalid, because $cart->$items becomes $cart->"" -$cart->$items = array("10" => 1); +// niepoprawnie, poniwa¿ $koszyk->$artykuly zamienia siê na $koszyk->"" +$koszyk->$artykuly = array("10" => 1); -// correct, but may or may not be what was intended: -// $cart->$myvar becomes $cart->items -$myvar = 'items'; -$cart->$myvar = array("10" => 1); +// poprawnie, ale mo¿e (ale nie musi) nie byæ tym, co zamierzali¶my: +// $koszyk->$zmienna staje siê $koszyk->artykuly +$zmienna = 'artykuly'; +$koszyk->$zmienna = array("10" => 1); </programlisting> </informalexample> <para> - Within a class definition, you do not know under which name the object will - be accessible in your program: At the time the Cart class was - written, it was unknown that the object will be named $cart or - $another_cart later. Thus, you cannot write $cart-&gt;items within - the Cart class itself. Instead, in order to be able to access it's own - functions and variables from within a class, one can use the - pseudo-variable $this which can be read as 'my own' or - 'current object'. Thus, '$this->items[$artnr] += $num' can - be read as 'add $num to the $artnr counter of my own items - array' or 'add $num to the $artnr counter of the items array - within the current object'. + Wewn±trz definicji klasy, nie wiesz pod jak± nazw± obiekt bêdzie dostêpny + dla twojego programu: w momencie pisania klasy Koszyk, nie by³o wiadomo, + ¿e obiekty bêd± siê nazywaæ $koszyk lub $inny_koszyk. W zwi±zku z tym nie + mo¿esz napisaæ $koszyk-&gt;artykuly wewn±trz klasy Koszyk. Zamiast tego, + aby uzyskaæ dostêp do funkcji i zmiennych zawartych w klasie, mo¿na u¿yæ + pseudo-zmiennej $this, która mo¿e byæ odczytana jako 'moje w³asne' lub + 'bie¿±cy obiekt'. A wiêc '$this-&gt;artykuly[$nrart] += $liczba' mo¿e byæ + odczytane jako 'dodaj $liczba do licznika $nrart z mojej w³asnej tablicy + artykuly' lub 'dodaj $liczba do licznika $nrartz tablicy artykuly zawartej + w bie¿±cym obiekcie'. </para> </sect1> @@ -185,123 +178,122 @@ <title><literal>extends</literal></title> <para> - Often you need classes with similar variables and functions - to another existing class. In fact, it is good practice to - define a generic class which can be used in all your - projects and adapt this class for the needs of each of your - specific projects. To facilitate this, classes can be - extensions of other classes. The extended or derived class - has all variables and functions of the base class (this is - called 'inheritance' despite the fact that nobody died) and what - you add in the extended definition. It is not possible to - substract from a class, that is, to undefine any existing - functions or variables. An extended class is always dependent - on a single base class, that is, multiple inheritance is - not supported. Classes are extended using the keyword 'extends'. + Bardzo czêsto zachodzi potrzeba stworzenia klasy o funkcjach i zmiennych + podobnych do ju¿ istniej±cej klasy. Zasadniczo dobrze jest stworzyæ + szablonow± klasê, która mo¿e byæ u¿yta we wszystkich twoich projektach i + przystosowywaæ j± do specyficznych potrzeb twojego projektu. Aby u³atwiæ + ten proces, klasy mog± byæ rozszerzeniami innych klas. Rozszerzone, lub + mówi±c inaczej 'dziedziczone', klasy maj± wszystkie zmienne i funkcje + klasy podstawowej (nazywa siê to dziedziczeniem, mimo ¿e nikt nie + umar³) oraz to co do niej doda³e¶ w definicji rozszerzenia. Nie mo¿na + odj±æ pewnych rzeczy z klasy podstawowej, czyli oddefiniowaæ istniej±cych + w klasie podstawowej funkcji i zmiennych. Rozszerzona klasa jest zawsze + zale¿na od jednej klasy bazowej - dziedziczenie wielokrotne nie jest + obs³ugiwane. Klasy mo¿na rozszerzyæ u¿ywaj±c s³owa kluczowego 'extends'. </para> <informalexample> <programlisting role="php"> -class Named_Cart extends Cart +class Nazwany_Koszyk extends Koszyk { - var $owner; + var $wlasciciel; - function set_owner ($name) + function ustaw_wlasciciela ($nazwa) { - $this->owner = $name; + $this->wlasciciel = $nazwa; } } </programlisting> </informalexample> <para> - This defines a class Named_Cart that has all variables and - functions of Cart plus an additional variable $owner and an - additional function set_owner(). You create a named cart the usual - way and can now set and get the carts owner. You can still use - normal cart functions on named carts: + Definiuje to klasê Nazwany_Koszyk, który ma wszystkie zmienne i funkcje + klasy Koszyk plus dodatkowa zmienna $wlasciciel i dodatkowa funkcja + ustaw_wlasciciela(). Nazwany koszyk tworzy siê normalnym sposobem. + Mo¿esz teraz ustawiaæ i pobieraæ nazwê w³a¶ciciela koszyka. Ca³y czas + mo¿esz u¿ywaæ zwyk³ych funkcji koszyka dla nazwanego koszyka: </para> <informalexample> <programlisting role="php"> -$ncart = new Named_Cart; // Create a named cart -$ncart->set_owner("kris"); // Name that cart -print $ncart->owner; // print the cart owners name -$ncart->add_item("10", 1); // (inherited functionality from cart) +$nkoszyk = new Nazwany_Koszyk; // Stwórz nazwany koszyk +$nkoszyk->ustaw_wlasciciela("kris"); // Nazwij koszyk +print $nkoszyk->wlasciciel; // Wy¶wietl w³a¶ciciela koszyka +$nkoszyk->dodaj_przedmiot("10", 1); // (funkcjonalno¶æ odziedziczona z + // koszyka) </programlisting> </informalexample> </sect1> <sect1 id="language.oop.constructor"> - <title><literal>Constructors</literal></title> + <title><literal>Konstruktory</literal></title> <caution> <simpara> - In PHP 3 and PHP 4 constructors behave differently. The PHP 4 - semantics are strongly preferred. + Konstruktory zachowuj± siê inaczej w PHP 3 i w PHP 4. Semantyka PHP 4 + jest mocno zalecana. </simpara> </caution> <para> - Constructors are functions in a class that are automatically - called when you create a new instance of a class with - <literal>new</literal>. In PHP 3, a - function becomes a constructor when it has the same name as - the class. In PHP 4, a function becomes a constructor, when - it has the same name as the class it is defined in - the - difference is subtle, but crucial (see below). + Konstruktory s± funkcjami klasy, które s± automatycznie wywo³ywane przy + tworzeniu nowej instancji klasy korzystaj±c z operatora + <literal>new</literal>. W PHP 3 funkcja staje siê konstruktorem kiedy ma + tak± sam± nazwê jak klasa. W PHP 4 funkcja staje siê konstruktorem, kiedy + ma tak± sam± nazwê jak klasa, w której ta funkcja zosta³a zdefiniowana - + ró¿nica jest subtelna, ale bardzo wa¿na (zobacz poni¿ej) </para> <informalexample> <programlisting role="php"> -// Works in PHP 3 and PHP 4. -class Auto_Cart extends Cart +// Dzia³a w PHP 3 i PHP 4. +class Auto_Koszyk extends Koszyk { - function Auto_Cart() + function Auto_Koszyk() { - $this->add_item ("10", 1); + $this->dodaj_artykul ("10", 1); } } </programlisting> </informalexample> <para> - This defines a class Auto_Cart that is a Cart plus a constructor - which initializes the cart with one item of article number "10" - each time a new Auto_Cart is being made with "new". Constructors - can take arguments and these arguments can be optional, which - makes them much more useful. To be able to still use the class - without parameters, all parameters to constructors should be - made optional by providing default values. + Ten kod definiujê klasê Auto_Koszyk, który jest klas± Koszyk pluc + konstruktor, który inicjalizuje wózek z jednym artyku³em "10" za ka¿dym + razem, kiedy Auto_Koszyk jest tworzony operatorem "new". Konstruktory mog± + pobieraæ argumenty i te argumenty mog± byæ opcjonalne, przez co s± jeszcze + bardziej u¿yteczne. Aby w dalszym ci±gu móc u¿ywaæ klasy bez parametrów, + wszystkie parametry konstruktora powinny staæ siê opcjonalne przez dodanie + domy¶lnych warto¶ci. </para> <informalexample> <programlisting role="php"> -// Works in PHP 3 and PHP 4. -class Constructor_Cart extends Cart +// Dzia³a w PHP 3 i PHP 4. +class Kontruktor_Koszyk extends Koszyk { - function Constructor_Cart($item = "10", $num = 1) + function Konstruktor_Koszyk($artykul = "10", $ilosc = 1) { - $this->add_item ($item, $num); + $this->dodaj_artykul ($artykul, $ilosc); } } -// Shop the same old boring stuff. +// Kup te same nudne rzeczy... -$default_cart = new Constructor_Cart; +$zwykly_koszyk = new Konstruktor_Koszyk; -// Shop for real... +// Czas na prawdziwe zakupy... -$different_cart = new Constructor_Cart("20", 17); +$inny_koszyk = new Konstruktor_Koszyk("20", 17); </programlisting> </informalexample> <caution> <simpara> - In PHP 3, derived classes and constructors have a number of - limitations. The following examples should be read carefully - to understand these limitations. + W PHP 3, dziedziczone klasy i konstruktory maj± wiele ograniczeñ. + Poni¿sze przyk³ady powinny byæ dok³adnie przeczytane w celu zrozumienia + tych ograniczeñ. </simpara> </caution> @@ -311,7 +303,7 @@ { function A() { - echo "I am the constructor of A.&lt;br>\n"; + echo "Jestem konstruktorem klasy A.&lt;br>\n"; } } @@ -319,27 +311,27 @@ { function C() { - echo "I am a regular function.&lt;br>\n"; + echo "Zwyk³a funkcja.&lt;br>\n"; } } -// no constructor is being called in PHP 3. +// W PHP 3 nie zostanie wywo³any ¿aden konstruktor. $b = new B; </programlisting> </informalexample> <para> - In PHP 3, no constructor is being called in the above example. - The rule in PHP 3 is: 'A constructor is a function of the same - name as the class.'. The name of the class is B, and there is - no function called B() in class B. Nothing happens. + W PHP 3 w powy¿szym przyk³adzie nie bêdzie wywo³any ¿aden konstruktor. + Zasad± PHP 3 jest: 'Konstruktor to funkcja o takiej samej nazwie jak + klasa'. Nazw± klasy jest B, a w klasie B nie ma funkcji o nazwie B(). Nic + siê nie dzieje. </para> <para> - This is fixed in PHP 4 by introducing another rule: If a class - has no constructor, the constructor of the base class is being - called, if it exists. The above example would have printed - 'I am the constructor of A.&lt;br>' in PHP 4. + Zosta³o to poprawione w PHP 4 przez wprowadzenie innej zasady: je¶li klasa + nie ma konstruktora, u¿ywany jest konstruktor klasy bazowej, je¶li taki + istnieje. W PHP 4 powy¿szy przyk³ad wy¶wietli 'Jestem konstruktorem klasy + A.&lt;br>'. </para> <informalexample> @@ -348,13 +340,13 @@ { function A() { - echo "I am the constructor of A.&lt;br>\n"; + echo "Jestem konstruktorem klasy A.&lt;br>\n"; } function B() { - echo "I am a regular function named B in class A.&lt;br>\n"; - echo "I am not a constructor in A.&lt;br>\n"; + echo "Jestem zwyk³± funkcj± o nazwie B w klasie A.&lt;br>\n"; + echo "Nie jestem konstruktorem w klasie A.&lt;br>\n"; } } @@ -362,53 +354,51 @@ { function C() { - echo "I am a regular function.&lt;br>\n"; + echo "Jestem zwyk³± funkcj±.&lt;br>\n"; } } -// This will call B() as a constructor. +// Wywo³a to B() jako konstruktor. $b = new B; </programlisting> </informalexample> <para> - In PHP 3, the function B() in class A will suddenly become a - constructor in class B, although it was never intended to be. - The rule in PHP 3 is: 'A constructor is a function of the same - name as the class.'. PHP 3 does not care if the function is - being defined in class B, or if it has been inherited. + W PHP 3, funkcja B() z klasy A niespodziewanie stanie siê konstruktorem w + klasie B, pomimo ¿e wcale nie mia³a nim byæ. Zasad± PHP 3 jest: + 'Konstruktor to funkcja o takiej samej nazwie co klasa'. PHP 3 nie + obchodzi czy funkcja zosta³a zdefiniowana w klasie B czy zosta³a + odziedziczona. </para> <para> - This is fixed in PHP 4 by modifying the rule to: 'A constructor - is a function of the same name as the class it is being defined - in.'. Thus in PHP 4, the class B would have no constructor function - of its own and the constructor of the base class would have been - called, printing 'I am the constructor of A.&lt;br>'. + Zosta³o to poprawione w PHP 4 przez modyfikacjê tej zasady do: + 'Konstruktor to funkcja o tej samej nazwie co klasa w której zosta³a + zdefiniowana'. W zwi±zku z tym w PHP 4 clasa B nie mia³aby w³asnego + konstruktora. Wywo³any by³by tylko konstruktor klasy bazowej, wy¶wietlaj±c + 'Jestem konstruktorem klasy A.&lt;br>'. </para> <caution> <simpara> - Neither PHP 3 nor PHP 4 call constructors of the base class - automatically from a constructor of a derived class. It is - your responsibility to propagate the call to constructors - upstream where appropriate. + Ani PHP 3 ani PHP 4 nie wywo³a automatycznie konstruktora klasy bazowej z + kontruktora klasy pochodnej. Twoim zadaniem jest propagacja wywo³añ + konstruktorów klas nadrzêdnych, je¶li to konieczne. </simpara> </caution> <note> <simpara> - There are no destructors in PHP 3 or PHP 4. You may use - <function>register_shutdown_function</function> instead - to simulate most effects of destructors. + Ani w PHP 3 ani w PHP 4 nie ma destruktorów. Zamiast tego mo¿esz u¿yæ + <function>register_shutdown_function</function> aby symulowaæ dzia³anie + destruktorów. </simpara> </note> <para> - Destructors are functions that are called automatically - when an object is destroyed, either with <function>unset</function> - or by simply going out of scope. There are no destructors - in PHP. + Destruktory s± funkcjami, które s± wywo³ywanie automatycznie kiedy obiekty + s± niszczone albo przez u¿ycie <function>unset</function> albo przez + wyj¶cie z zasiêgu. W PHP nie ma destruktorów. </para> </sect1> @@ -417,82 +407,76 @@ <caution> <simpara> - The following is valid for PHP 4 only. + Poni¿sze dotyczy tylko PHP 4. </simpara> </caution> <para> - Sometimes it is useful to refer to functions and variables - in base classes or to refer to functions in classes that - have not yet any instances. The :: operator is being used - for this. + Czasami dobrze jest odnosiæ siê do funkcji i zmiennych w klasie bazowej + lub odnosiæ siê do funkcji i klas które nie maj± jeszcze instancji. S³u¿y + do tego operator ::. </para> <informalexample> <programlisting role="php"> class A { - function example() + function przyklad() { - echo "I am the original function A::example().&lt;br>\n"; + echo "Jestem orginaln± funkcj± A::przyklad().&lt;br>\n"; } } class B extends A { - function example() + function przyklad() { - echo "I am the redefined function B::example().&lt;br>\n"; - A::example(); + echo "Jestem przedefiniowan± funkcj± B::przyklad().&lt;br>\n"; + A::przyklad(); } } -// there is no object of class A. -// this will print -// I am the original function A::example().&lt;br> -A::example(); +// nie ma obiektu klasy A. +// poni¿sze wy¶wietli +// Jestem orginaln± funkcj± A::przyklad().&lt;br> +A::przyklad(); -// create an object of class B. +// stwórz nowy obiekt klasy B. $b = new B; -// this will print -// I am the redefined function B::example().&lt;br> -// I am the original function A::example().&lt;br> -$b->example(); +// poni¿sze wy¶wietli +// Jestem przedefiniowan± funkcj± B::przyklad().&lt;br> +// Jestem orginaln± funkcj± A::przyklad().&lt;br> +$b->przyklad(); </programlisting> </informalexample> <para> - The above example calls the function example() in - class A, but there is no object of class A, so that - we cannot write $a->example() or similar. Instead we - call example() as a 'class function', that is, as a - function of the class itself, not any object of that - class. + Powy¿szy przek³ad wywo³uje funkcjê przyklad() z klasy A, ale nie tworz±c + obiektu tej klasy, przez co nie mo¿emy napisaæ nic w stylu $a->przyklad(). + Zamiast tego mo¿emy wywo³aæ przyklad() jako 'funkcjê klasy', czyli jako + funkcjê tylko klasy, nie ¿adnego obiektu tej klasy. </para> <para> - There are class functions, but there are no class variables. - In fact, there is no object at all at the time of the call. - Thus, a class function may not use any object variables (but - it can use local and global variables), and it may no use - $this at all. + Istniej± funkcje klasy, ale nie ma zmiennych klasy. Faktycznie w czasie + wykonania nie ma ¿adnego obiektu. W zwi±zku z tym funkcje klasy nie mog± + u¿ywaæ ¿adnych zmiennych obiektu (ale mog± u¿ywaæ zmiennych lokalnych i + globalnych), ani w ogóle $this. </para> <para> - In the above example, class B redefines the function example(). - The original definition in class A is shadowed - and no longer available, unless you are refering specifically - to the implementation of example() in class A using the - ::-operator. Write A::example() to do this (in fact, you - should be writing parent::example(), as shown in the next - section). + W powy¿szym przyk³adzie, klasa B przedefiniowuje funkcjê przyklad(). + Orginalna definicja z klasy A jest zas³oniêta i niedostêpna, chyba ¿e + odwo³asz siê do konkretnej implementacji poprzez operator ::. Aby to + zrobiæ, napisz A::przyklad() (powiniene¶ jednak u¿yæ parent::przyklad(), + tak jak to pokazano w nastêpnej czê¶ci). </para> <para> - In this context, there is a current object and it may - have object variables. Thus, when used from WITHIN an - object function, you may use $this and object variables. + W tym kontek¶cie, istnieje bie¿±cy obiekt i który ma zmienne obiektu. W + zwi±zu z tym je¶li funkcja jest u¿yta Z WEWN¡TRZ funkcji obiektu, mo¿esz + u¿ywaæ $this i zmiennych obiektu. </para> </sect1> @@ -501,91 +485,85 @@ <title><literal>parent</literal></title> <para> - You may find yourself writing code that refers to - variables and functions in base classes. This is - particularly true if your derived class is a refinement - or specialisation of code in your base class. + Mo¿e siê zdarzyæ, ¿e bêdziesz pisa³ kod, który odnosi siê do funkcji i + zmiennych klasy bazowej. Jest to mo¿liwe je¶li twoja klasa pochodna jest + u¶ci¶leniem lub specjalizacj± klasy bazowej. </para> <para> - Instead of using the literal name of the base class in your - code, you should be using the special name - <literal>parent</literal>, which refers to the name of your - base class as given in the <literal>extends</literal> - declation of your class. By doing this, you avoid using the - name of your base class in more than one place. Should - your inheritance tree change during implementation, the - change is easily made by simply changing the - <literal>extends</literal> declaration of your class. + Zamiast jawnego podawania nazwy klasy bazowej w kodzie, powiniene¶ u¿yæ + specjalnej nazwy <literal>parent</literal>, która odnosi siê do nazwy klasy + bazowej podanej przy <literal>extends</literal> podczas deklaracji twojej + klasy. Robi±c to, unikasz u¿ycia nazwy klasy bazowej w wiêcej ni¿ jednym + miejscu. Je¶li twoje drzewo dziedziczenia zmieni³oby siê podczas + implementacji, zmiana bêdzie wymaga³a poprawki tylko w jednym miejscu - + przy s³owie kluczowym <literal>extends</literal> w deklaracji klasy. </para> <informalexample> <programlisting role="php"> class A { - function example() + function przyklad() { - echo "I am A::example() and provide basic functionality.&lt;br>\n"; + echo "Jestem A::przyklad() I dostarczam podstawow± funkcjonalno¶æ.&lt;br>\n"; } } class B extends A { - function example() + function przyklad() { - echo "I am B::example() and provide additional functionality.&lt;br>\n"; - parent::example(); + echo "Jestem B::przyklad() i dostarczam dodatkow± funkcjonalno¶æ.&lt;br>\n"; + parent::przyklad(); } } $b = new B; -// This will call B::example(), which will in turn call A::example(). -$b->example(); +// Wywo³a to B::przyklad(), który z kolei wywo³a A::przyklad(). +$b->przyklad(); </programlisting> </informalexample> </sect1> <sect1 id="language.oop.serialization"> - <title>Serializing objects - objects in sessions</title> + <title>Serializacja obiektów - obiekty w sesjach</title> <note> <simpara> - In PHP 3, objects will lose their class association - throughout the process of serialization and unserialization. - The resulting variable is of type object, but has no class - and no methods, thus it is pretty useless (it has become - just like an array with a funny syntax). + W PHP 3 obiekty trac± powi±zania miêdzy klasami w czasie procesu + serializacji i odserializacji. Wynikowa zmienna bêdzie typu obiekt, ale + bez klasy i bez metod, a wiêc w zasadzie bezu¿yteczn± (zostanie poprostu + zmienn± ze ¶mieszn± sk³adni±). </simpara> </note> <caution> <simpara> - The following information is valid for PHP 4 only. + Poni¿sze informacje dotycz± tylko PHP 4. </simpara> </caution> <para> - <function>serialize</function> returns a string containing a - byte-stream representation of any value that can be stored in - PHP. <function>unserialize</function> can use this string to - recreate the original variable values. Using serialize to - save an object will save all variables in an object. The - functions in an object will not be saved, only the name of - the class. + <function>serialize</function> zwraca string bêd±cy reprezentacj± dowolnej + warto¶ci, która mo¿e byæ przechowywana przez PHP. + <function>unserialize</function> mo¿e u¿yæ tego stringu aby odtworzyæ + orginalne warto¶ci zmiennej. U¿ycie serializacji do zapisania obiektu + zachowa wszystkie zmienne z obiektu. Zapisane nie bêd± funkcje z obiektu, a + jedynie nazwa klasy. </para> <para> - In order to be able to <function>unserialize</function> an - object, the class of that object needs to be defined. That - is, if you have an object $a of class A on page1.php and - serialize this, you'll get a string that refers to class A - and contains all values of variabled contained in $a. If - you want to be able to unserialize this on page2.php, - recreating $a of class A, the definition of class A must - be present in page2.php. This can be done for example - by storing the class defintion of class A in an include - file and including this file in both page1.php and page2.php. + Aby istnia³a mo¿liwo¶æ u¿ycia funkcji <function>unserialize</function> do + odzyskania obiektu, musi byæ zdefiniowana klasa tego obiektu. Oznacza to, + ¿e je¶li obiekt $a klasy A istnieje na page1.php i zserializujesz go, + otrzymasz string, który odnosi siê do klasy A i zawiera warto¶ci wszystkich + zmiennych zawartych w $a. Je¶li chcesz, aby istnia³a mo¿liwo¶æ + odserializacji tego obiektu na page2.php, na page2.php musi istnieæ + definicja klasy A. Mo¿na to zrobiæ na przyk³ad przez przechowywanie + definicji klasy A w zewnêtrznym pliku includowanym przez page1.php i + page2.php. </para> <informalexample> @@ -593,11 +571,11 @@ classa.inc: class A { - var $one = 1; + var $jeden = 1; - function show_one() + function pokaz_jeden() { - echo $this->one; + echo $this->jeden; } } @@ -606,115 +584,110 @@ $a = new A; $s = serialize($a); - // store $s somewhere where page2.php can find it. + // przechowaj $s gdzie¶, gdzie page2.php bêdzie mog³a go znale¼æ $fp = fopen("store", "w"); fputs($fp, $s); fclose($fp); page2.php: - // this is needed for the unserialize to work properly. + // to jest niezbêdne aby funkcja unserialize dzia³a³a prawid³owo. include("classa.inc"); $s = implode("", @file("store")); $a = unserialize($s); - // now use the function show_one() of the $a object. - $a->show_one(); + // teraz u¿yj funkcji pokaz_jeden z obiektu $a. + $a->pokaz_jeden(); </programlisting> </informalexample> <para> - If you are using sessions and use <function>session_register</function> - to register objects, these objects are serialized automatically - at the end of each PHP page, and are unserialized automatically on - each of the following pages. This basically means that these objects - can show up on any of your pages once they become part of your - session. + Je¶li u¿ywasz sesji i <function>session_register</function> do rejestracji + obiektów, te obiekty s± serializowane automatycznie na koñcu ka¿dej strony + PHP i odserializowane automatycznie na ka¿dej z nastêpnych stron. + Zasadniczo znaczy to, ¿e te obiekty mog± pokazaæ siê na dowolnej z twoich + stron je¶li tylko stan± siê czê¶ci± twojej sesji. </para> <para> - It is strongly recommended that you include the class - definitions of all such registered objects on all of your - pages, even if you do not actually use these classes on all - of your pages. If you don't and an object is being - unserialized without its class definition being present, it - will lose its class association and become an object of class - <literal>stdClass</literal> without any functions available - at all, that is, it will become quite useless. + Mocno zalecane jest includowanie definicji klas wszystkich zarejestrowanych + obiektów na wszystkich twoich stronach, nawet je¶li nie u¿ywasz tych + zmiennych na twoich stronach. Je¶li tego nie zrobisz a obiekty zostan± + odserializowane bez definicji klasy, powi±zania klasowe zostan± utracone a + obiek stanie siê obiektem klasy <literal>stdClass</literal> bez ¿adnych + dostêpnych funkcji, a wiêc bêdzie ca³kiem bezu¿yteczny. </para> <para> - So if in the example above $a became part of a session by - running <literal>session_register("a")</literal>, you should - include the file <literal>classa.inc</literal> on all of your - pages, not only page1.php and page2.php. + A wiêc je¶li w powy¿szym przyk³adzie $a stanie siê czê¶ci± sesji przez + wywo³anie <literal>session_register("a")</literal>, powinieneæ includowaæ + plik <literal>classa.inc</literal> na wszystkich stronach, nie tylko + page1.php i page2.php. </para> </sect1> <sect1 id="language.oop.magic-functions"> - <title>The magic functions <literal>__sleep</literal> and <literal>__wakeup</literal></title> + <title>Magiczne funkcje <literal>__sleep</literal> i <literal>__wakeup</literal></title> <para> - <function>serialize</function> checks if your class has a function with - the magic name <literal>__sleep</literal>. If so, that function is - being run prior to any serialization. It can clean up the object - and is supposed to return an array with the names of all variables - of that object that should be serialized. + <function>serialize</function> sprawdza, czy twoja klasa zawiera funkcjê o + magicznej nazwie <literal>__sleep</literal>. Je¶li tak, ta funkcja jest + wywo³ywana przed ka¿d± serializacj±. Mo¿e ona czy¶ciæ obiekt i powinna + zwracaæ tablicê z nazwami wszystkich zmiennych obiektu, które powinny byæ + serializowane. </para> <para> - The intended use of <literal>__sleep</literal> is to close any - database connections that object may have, committing pending - data or perform similar cleanup tasks. Also, the function is - useful if you have very large objects which need not be - saved completely. + Za³o¿onym u¿yciem <literal>__sleep</literal> jest zamkniêcie wszystkich + po³±czeñ do baz danych, które obiekt mo¿e utrzymywaæ, zatwierdzenie + wszystkich oczekuj±cych danych lub wykonanie innych podobnych czynno¶ci + czyszcz±cych. Funkcja ta jest tak¿e przydatna je¶li masz bardzo du¿e + obiekty, które nie musz± byæ zachowane w ca³o¶ci. </para> <para> - Conversely, <function>unserialize</function> checks for the - presence of a function with the magic name - <literal>__wakeup</literal>. If present, this function can - reconstruct any ressources that object may have. + Analogicznie, <function>unserialize</function> sprawdza czy istnieje + funkcja o magicznej nazwie <literal>__wakeup</literal>. Je¶li tak, funkcja + mo¿e rekonstruowaæ dowolne zasoby które obiekt mo¿e posiadaæ. </para> <para> - The intended use of <literal>__wakeup</literal> is to - reestablish any database connections that may have been lost - during serialization and perform other reinitialization - tasks. + Za³o¿onym u¿yciem <literal>__wakeup</literal> jest odnowienie po³±czeñ z + bazami danych, które mog³y zostac utracone w procesie serializacji, oraz + wykonanie innych czynno¶ci odbudowuj±cych obiekt. </para> </sect1> <sect1 id="language.oop.newref"> - <title>References inside the constructor</title> + <title>Referencje wewn±trz konstruktora</title> <para> - Creating references within the constructor can lead to confusing - results. This tutorial-like section helps you to avoid problems. + Tworzenie referencji wewn±trz konstruktora mo¿e prowadziæ do dziwnych + efektów. Ten rozdzia³ ma pomóc w unikaniu takich problemów. <informalexample> <programlisting role="php"> class Foo { - function Foo($name) + function Foo($nazwa) { - // create a reference inside the global array $globalref + // stworz referencje wewnatrz globalnej tablicy $globalref global $globalref; $globalref[] = &amp;$this; - // set name to passed value - $this->setName($name); - // and put it out - $this->echoName(); + // ustaw nazwê na przekazan± warto¶æ + $this->ustawNazwe($nazwa); + // i wy¶wietl j± + $this->wyswietlNazwe(); } - function echoName() + function wyswietlNazwe() { - echo "&lt;br&gt;",$this->name; + echo "&lt;br&gt;",$this->nazwa; } - function setName($name) + function ustawNazwe($nazwa) { - $this->name = $name; + $this->nazwa = $nazwa; } } </programlisting> @@ -722,86 +695,87 @@ </para> <para> - Let us check out if there is a difference between - <varname>$bar1</varname> which has been created using - the copy <literal>=</literal> operator and - <varname>$bar2</varname> which has been created using - the reference <literal>=&amp;</literal> operator... + Sprawd¼my, czy jest jaka¶ ró¿nica pomiêdzy + <varname>$bar1</varname>, który jest tworzony przy pomocy operatora + przypisania <literal>=</literal>, a <varname>$bar2</varname>, który zosta³ + stworzony u¿ywaj±c operatora referencji <literal>=&amp;</literal>... <informalexample> <programlisting role="php"> -$bar1 = new Foo('set in constructor'); -$bar1->echoName(); -$globalref[0]->echoName(); - -/* output: -set in constructor -set in constructor -set in constructor */ - -$bar2 =&amp; new Foo('set in constructor'); -$bar2->echoName(); -$globalref[1]->echoName(); - -/* output: -set in constructor -set in constructor -set in constructor */ +$bar1 = new Foo('ustawione w konstruktorze'); +$bar1->wyswietlNazwe(); +$globalref[0]->wyswietlNazwe(); + +/* wyj¶cie: +ustawione w konstruktorze +ustawione w konstruktorze +ustawione w konstruktorze */ + +$bar2 =&amp; new Foo('ustawione w konstruktorze'); +$bar2->wyswietlNazwe(); +$globalref[1]->wyswietlNazwe(); + +/* wyj¶cie: +ustawione w konstruktorze +ustawione w konstruktorze +ustawione w konstruktorze */ </programlisting> </informalexample> </para> <para> - Apparently there is no difference, but in fact there is a - very significant one: <varname>$bar1</varname> and - <varname>$globalref[0]</varname> are _NOT_ referenced, they - are NOT the same variable. This is because "new" does not - return a reference by default, instead it returns a copy. + Wydaje siê, ¿e nie ma ¿adnej ró¿nicy, ale na prawdê jest jedna, i to + bardzo istotna: <varname>$bar1</varname> i + <varname>$globalref[0]</varname> <emphasis>NIE</emphasis> s± referencjami, + <emphasis>NIE</emphasis> s± t± sam± zmienna. Dzieje siê tak, poniewa¿ + "new" nie zwraca domy¶lnie referencji, ale kopiê. <note> <simpara> - There is no performance loss (since PHP 4 and up use reference - counting) returning copies instead of references. On the - contrary it is most often better to simply work with copies - instead of references, because creating references takes some - time where creating copies virtually takes no time (unless none - of them is a large array or object and one of them gets changed - and the other(s) one(s) subsequently, then it would be wise to - use references to change them all concurrently). + Zwracanie kopii zamiast referencji nie powoduje utraty wydajno¶ci (od + PHP 4 u¿ywane jest zliczanie referencji). Jednak¿e zazwyczaj lepiej jest + pracowaæ poprostu z kopiami zamiast referencji, poniewaæ tworzenie + referencji zabiera trochê czasu, podczas gdy tworzenie kopii obiektów + teoretycznie w ogóle nie zabiera czasu (chyba ¿e która¶ z tych zmiennych + jest du¿± tablic± lub obiektem i jedno z nich ulega zmianie, po czym tej + samej zmianie ulegaj± pozosta³e zmienne; wtedy lepiej jest u¿yæ + referencji do zmieniania ich równolegle). </simpara> </note> - To prove what is written above let us watch the code below. + Aby udowodniæ to, co zosta³o zapisane powy¿ej, przyjrzyjmy siê poni¿szemu + programowi. <informalexample> <programlisting role="php"> -// now we will change the name. what do you expect? -// you could expect that both $bar1 and $globalref[0] change their names... -$bar1->setName('set from outside'); - -// as mentioned before this is not the case. -$bar1->echoName(); -$globalref[0]->echoName(); - -/* output: -set from outside -set in constructor */ - -// let us see what is different with $bar2 and $globalref[1] -$bar2->setName('set from outside'); - -// luckily they are not only equal, they are the same variable -// thus $bar2->name and $globalref[1]->name are the same too -$bar2->echoName(); -$globalref[1]->echoName(); - -/* output: -set from outside -set from outside */ +// teraz zmienimy nazwê. czego siê spodziewasz? +// mo¿esz siê spodziewaæ, ¿e i $bar1 i $globalref[0] zmieni± swoje nazwy... +$bar1->ustawNazwe('ustawiona z zewn±trz'); + +// jak napisano powy¿ej, nic takiego siê nie stanie +$bar1->wyswietlNazwe(); +$globalref[0]->wyswietlNazwe(); + +/* wyj¶cie: +ustawiona z zewn±trz +ustawiona w konstruktorze */ + +// zobaczmy co siê dzieje z $bar2 i $globalref[1] +$bar2->ustawNazwe('ustawiona z zewn±trz'); + +// na szczê¶cie ta zmienna nie zachowuje siê jak ta z poprzedniego przypadku +// s± to te same zmienne, z wiêc $bar2->nazwa i $globalref[1]->nazwa s± tak¿e +// tymi samymi zmiennymi +$bar2->wyswietlNazwe(); +$globalref[1]->wyswietlNazwe(); + +/* wyj¶cie: +ustawiona z zewn±trz +ustawiona z zewn±trz */ </programlisting> </informalexample> </para> <para> - Another final example, try to understand it. + Ustatni przyk³ad. Postaraj siê go zrozumieæ/ <informalexample> <programlisting role="php"> @@ -809,19 +783,19 @@ { function A($i) { - $this->value = $i; - // try to figure out why we do not need a reference here + $this->wartosc = $i; + // domy¶l siê dlaczego nie potrzebujemy tutaj referencji $this->b = new B($this); } - function createRef() + function stworzRef() { $this->c = new B($this); } - function echoValue() + function wyswietlWartosc() { - echo "&lt;br&gt;","class ",get_class($this),': ',$this->value; + echo "&lt;br&gt;","klasa ",get_class($this),': ',$this->value; } } @@ -833,35 +807,34 @@ $this->a = &amp;$a; } - function echoValue() + function wyswietlWartosc() { - echo "&lt;br&gt;","class ",get_class($this),': ',$this->a->value; + echo "&lt;br&gt;","klasa ",get_class($this),': ',$this->a->value; } } - -// try to undestand why using a simple copy here would yield -// in an undesired result in the *-marked line +// spróbuj zrozumieæ dlaczego u¿ycie tu prostego kopiowania mo¿e powodowaæ +// nieporz±dany efekt w linii uznaczonej znaczkiem '*' $a =&amp; new A(10); -$a->createRef(); +$a->stworzRef(); -$a->echoValue(); -$a->b->echoValue(); -$a->c->echoValue(); +$a->wyswietlWartosc(); +$a->b->wyswietlWartosc(); +$a->c->wyswietlWartosc(); $a->value = 11; -$a->echoValue(); -$a->b->echoValue(); // * -$a->c->echoValue(); +$a->wyswietlWartosc(); +$a->b->wyswietlWartosc(); // * +$a->c->wyswietlWartosc(); /* -output: -class A: 10 -class B: 10 -class B: 10 -class A: 11 -class B: 11 -class B: 11 +wyj¶cie: +klasa A: 10 +klasa B: 10 +klasa B: 10 +klasa A: 11 +klasa B: 11 +klasa B: 11 */ </programlisting> </informalexample>
« previous php.doc (#969338325) next »