cvs: phpdoc-sl /language oop.xml
| From: | Dejan Markic | Date: | Sun, 12 Jan 2003 20:45:49 +0000 |
| Subject: | cvs: phpdoc-sl /language oop.xml | ||
| Groups: | php.doc.sl | ||
| Request: | Send a blank email to doc-sl+get-43@lists.php.net to get a copy of this message | ||
dejan Sun Jan 12 15:45:49 2003 EDT
Modified files:
/phpdoc-sl/language oop.xml
Log:
Started to work on this one.
Index: phpdoc-sl/language/oop.xml diff -u phpdoc-sl/language/oop.xml:1.1 phpdoc-sl/language/oop.xml:1.2 --- phpdoc-sl/language/oop.xml:1.1 Wed Sep 4 10:02:42 2002 +++ phpdoc-sl/language/oop.xml Sun Jan 12 15:45:49 2003 @@ -1,14 +1,14 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <!-- $EN-Revision: 1.36 Maintainer: dejan Status: working --> <chapter id="language.oop"> - <title>Classes and Objects</title> + <title>Razredi in objekti</title> <sect1 id="keyword.class"> - <title><literal>class</literal></title> + <title><literal>razred</literal></title> <para> - A class is a collection of variables and functions working with - these variables. A class is defined using the following syntax: + Razred je zbirka spremenljivk in funkcij, ki delajo s temi spremenljivkami. + razred definiramo z naslednjo sintakso: <informalexample> <programlisting role="php"> @@ -44,50 +44,48 @@ </para> <para> - This defines a class named Cart that consists of an associative - array of articles in the cart and two functions to add and remove - items from this cart. + Zgornje definira razred z imenom Cart, ki ga sestavlja asociativna + tabela artiklov in dve funkciji za dodajanje in odstranjevanje + predmetov. </para> <caution> <simpara> - The following cautionary notes are valid for PHP 4. + Naslednja opozorila so veljavna za PHP 4. </simpara> <simpara> - The name <literal>stdClass</literal> is used interally by - Zend and is reserved. You cannot have a class named - <literal>stdClass</literal> in PHP. + Ime <literal>stdClass</literal> uporablja Zend interno in je zato + zasedeno. Uporaba razreda, ki ima ime <literal>stdClass</literal>, + v PHP-ju ni možna. </simpara> <simpara> - The function names <literal>__sleep</literal> and - <literal>__wakeup</literal> are magical in PHP classes. You - cannot have functions with these names in any of your - classes unless you want the magic functionality associated - with them. See below for more information. + Funkciji <literal>__sleep</literal> in <literal>__wakeup</literal> sta + posebni funkciji v PHP razredih. Funkcije s tem imenom ne morate imeti v + vaših razredih, razen če bi radi uporabili njuno posebno + funkcionalnost. Spodaj se nahaja več informacij. </simpara> <simpara> - PHP reserves all function names starting with __ as magical. - It is recommended that you do not use function names with - __ in PHP unless you want some documented magic functionality. + PHP si je rezervilal vse funkcije ki se pričnejo z __ kot posebne. + Priporočljivo je, da ne uporabljate funkcij z __ razen če bi + radi uporabili kak&353;o od dokumentiranih funkcionalnosti. </simpara> </caution> <note> <simpara> - In PHP 4, only constant initializers for <literal>var</literal> - variables are allowed. To initialize variables with non-constant - values, you need an initialization function which is called - automatically when an object is being constructed from the - class. Such a function is called a constructor (see below). + V PHP 4 so dovoljeni samo initializatorji konstant <literal>var</literal> + Da bi inicializirali spremenljivko z ne-konstantno vrednostjo, morate imeti + inicializacijsko fukcijo, ki je klicana avtomatično ko kreiramo objekt + iz razreda. Taka funkcija se imenuje konstruktor (poglejte spodaj). </simpara> <informalexample> <programlisting role="php"> <![CDATA[ <?php -/* None of these will work in PHP 4. */ +/* Nic od tega ne bo delalo v PHP 4. */ class Cart { var $todays_date = date("Y-m-d"); @@ -96,7 +94,7 @@ var $items = array("VCR", "TV"); } -/* This is how it should be done. */ +/* To je pravilen postopek. */ class Cart { var $todays_date; @@ -108,7 +106,7 @@ { $this->todays_date = date("Y-m-d"); $this->name = $GLOBALS['firstname']; - /* etc. . . */ + /* itd. . . */ } } ?> @@ -118,9 +116,8 @@ </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. + Razredi so tipi, ubistvu so načrti za dejanske spremenljivke. Vi morate + ustvariti spremenljivko željenega tipa z operatorjem <literal>new</literal>. </para> <informalexample> @@ -137,41 +134,38 @@ </informalexample> <para> - This creates the objects $cart and $another_cart, both of - the class Cart. The function add_item() of the $cart object - is being called to add 1 item of article number 10 to the - $cart. 3 items of article number 0815 are being added to - $another_cart. + To ustvari objekta $cart in $another_cart, oba razreda Cart. Funkcija + add_item() $cart objekta je klicana za dodajanje enega predmeta, ki ima + številko artikla 10, v objekt $cart. Trije predmeti, ki imajo številko + artikla 0815 so dodani v $another_cart. </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 ->. - Thus, the names $cart->items and $another_cart->items - name two different variables. Note that the variable is - named $cart->items, not $cart->$items, that is, a - variable name in PHP has only a single dollar sign. + Oba objekta, $cart in $another_cart imata funkciji add_item(), + remove_item in spremenljivke. To so različne funkcije in + spremenljivke. Objekte si lahko predstavljate kot direktorije v + datotečnem sistemu. V datotečnem sistemu imate lahko dve + različ:ni datoteki README.TXT dokler sta ti dve datoteki vsaka v + svojem direktoriju. Tako kot pri direktorijih, kjer morate vpisati celotno + pot iz vrhovnega direktorija, morate tu uporabiti celotno ime funkcije ki jo + želite klicati. V PHP-ju bi bil vrhovni direktorij globalni imenski + prostor in ločilec za direktorije ->. + Tako so imena $vart->items in $another_cart->items + imena za dve različni spremenljivki. Zapomnite si da je spremenljivka + imenovana $vart->items in ne $cart->$items. To poemni, da ima + spremenljivka v PHP-ju samo en dolar znak. </para> <informalexample> <programlisting role="php"> <![CDATA[ -// correct, single $ +// pravilno, enojni $ $cart->items = array("10" => 1); -// invalid, because $cart->$items becomes $cart->"" +// napacno, ker $cart->$items postane $cart->"" $cart->$items = array("10" => 1); -// correct, but may or may not be what was intended: +// pravilno, ce je to kar ste zeleli: // $cart->$myvar becomes $cart->items $myvar = 'items'; $cart->$myvar = array("10" => 1); @@ -180,24 +174,21 @@ </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->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'. + V definiciji razreda nevemo pod kaksnim imenom bo objekt dostopen v nasem programu: + v trenutku, ko smo pisali razred Cart, ime objekta #cart ali $another_cart + ni bilo zmano. Torej ne morate pisati $cart->items v samem Cart razredu. + Namesto tega, če želimo dostopati do funkcij in spremenljivk + razreda v razredu samem, uporabimo izmišljeno spremenljivko $this, ki si + jo lahko predstavljamo kot 'moje' ali 'trenutni objekt'. Torej bi + '$this->items[$artnr] += $num' lahko prebrali kot 'dodaj $num k $artnr + števcu v moji tabeli predmetov' ali 'dodaj $num k $artnr števcu + v tabeli predmetov v trenutnem objektu'. </para> <note> <para> - There are some nice functions to handle classes and objects. You might want - to take a look at the <link linkend="ref.classobj">Class/Object - Functions</link> + Obstaja kar nekaj zanimivh funkcij za upravljanje razredov in objektov. Oglejte + si <link linkend="ref.classobj">Razredne/Objektne Funkcije</link> </para> </note> </sect1> @@ -206,19 +197,18 @@ <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'. + Velikokrat potrebujete razrede s podobnimi spremenljivkami in + funkcijami v drugem obstoječem razredu. Pravzaprav je dobra + praksa definirati splošni razred, ki ga lahko uporabite v vseh + vaših projektih in ga prilagajate vsakemu vašemu + specifičnem projektu. Da si olajšate to delo, so razredi + lahko razširitev drugih razredov. Razširjen ali izpeljan + razred ima vse funkcije in spremenljivke osnovnega razreda + (temu rešemo 'podedovanje', šeprav ni nihše umrl) in + kar mu dodate v extends definiciji. Odstranjevanje funkcij ali + spremenljivk ni možno, torej da bi izbrisali kaksno obstoječo + funkcijo ali spremenljivko. Razširjeni razred je vedno odvisen od + osnovnega razreda. Razredi so razširjeni z uporabo 'extends'. </para> <informalexample> @@ -238,20 +228,20 @@ </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: + Zgornje definira razred Named_Cart, ki ima vse spremenljivke in + funkcije razreda Cart in dodatno spremenljivko $owner in dodatno + funkcijo set_owner(). 'Named cart' ustvarite normalno in lahko + sedaj nastavite ali dobite vrednost $owner. Seveda lahko uporabite vse + funkcije in spremenljivke Cart razreda: </para> <informalexample> <programlisting role="php"> <![CDATA[ -$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) +$ncart = new Named_Cart; // Ustvari objekt Named_Cart razreda +$ncart->set_owner("kris"); // Uporabimo fukcijo v Named_Cart razredu +print $ncart->owner; // Uporabimo spremenljivko v Named_Cart razredu +$ncart->add_item("10", 1); // (podedovana funkcionalnost iz Cart razreda) ]]> </programlisting> </informalexample>
Index: phpdoc-sl/language/oop.xml diff -u phpdoc-sl/language/oop.xml:1.1 phpdoc-sl/language/oop.xml:1.2 --- phpdoc-sl/language/oop.xml:1.1 Wed Sep 4 10:02:42 2002 +++ phpdoc-sl/language/oop.xml Sun Jan 12 15:45:49 2003 @@ -1,14 +1,14 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <!-- $EN-Revision: 1.36 Maintainer: dejan Status: working --> <chapter id="language.oop"> - <title>Classes and Objects</title> + <title>Razredi in objekti</title> <sect1 id="keyword.class"> - <title><literal>class</literal></title> + <title><literal>razred</literal></title> <para> - A class is a collection of variables and functions working with - these variables. A class is defined using the following syntax: + Razred je zbirka spremenljivk in funkcij, ki delajo s temi spremenljivkami. + razred definiramo z naslednjo sintakso: <informalexample> <programlisting role="php"> @@ -44,50 +44,48 @@ </para> <para> - This defines a class named Cart that consists of an associative - array of articles in the cart and two functions to add and remove - items from this cart. + Zgornje definira razred z imenom Cart, ki ga sestavlja asociativna + tabela artiklov in dve funkciji za dodajanje in odstranjevanje + predmetov. </para> <caution> <simpara> - The following cautionary notes are valid for PHP 4. + Naslednja opozorila so veljavna za PHP 4. </simpara> <simpara> - The name <literal>stdClass</literal> is used interally by - Zend and is reserved. You cannot have a class named - <literal>stdClass</literal> in PHP. + Ime <literal>stdClass</literal> uporablja Zend interno in je zato + zasedeno. Uporaba razreda, ki ima ime <literal>stdClass</literal>, + v PHP-ju ni možna. </simpara> <simpara> - The function names <literal>__sleep</literal> and - <literal>__wakeup</literal> are magical in PHP classes. You - cannot have functions with these names in any of your - classes unless you want the magic functionality associated - with them. See below for more information. + Funkciji <literal>__sleep</literal> in <literal>__wakeup</literal> sta + posebni funkciji v PHP razredih. Funkcije s tem imenom ne morate imeti v + vaših razredih, razen če bi radi uporabili njuno posebno + funkcionalnost. Spodaj se nahaja več informacij. </simpara> <simpara> - PHP reserves all function names starting with __ as magical. - It is recommended that you do not use function names with - __ in PHP unless you want some documented magic functionality. + PHP si je rezervilal vse funkcije ki se pričnejo z __ kot posebne. + Priporočljivo je, da ne uporabljate funkcij z __ razen če bi + radi uporabili kak&353;o od dokumentiranih funkcionalnosti. </simpara> </caution> <note> <simpara> - In PHP 4, only constant initializers for <literal>var</literal> - variables are allowed. To initialize variables with non-constant - values, you need an initialization function which is called - automatically when an object is being constructed from the - class. Such a function is called a constructor (see below). + V PHP 4 so dovoljeni samo initializatorji konstant <literal>var</literal> + Da bi inicializirali spremenljivko z ne-konstantno vrednostjo, morate imeti + inicializacijsko fukcijo, ki je klicana avtomatično ko kreiramo objekt + iz razreda. Taka funkcija se imenuje konstruktor (poglejte spodaj). </simpara> <informalexample> <programlisting role="php"> <![CDATA[ <?php -/* None of these will work in PHP 4. */ +/* Nic od tega ne bo delalo v PHP 4. */ class Cart { var $todays_date = date("Y-m-d"); @@ -96,7 +94,7 @@ var $items = array("VCR", "TV"); } -/* This is how it should be done. */ +/* To je pravilen postopek. */ class Cart { var $todays_date; @@ -108,7 +106,7 @@ { $this->todays_date = date("Y-m-d"); $this->name = $GLOBALS['firstname']; - /* etc. . . */ + /* itd. . . */ } } ?> @@ -118,9 +116,8 @@ </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. + Razredi so tipi, ubistvu so načrti za dejanske spremenljivke. Vi morate + ustvariti spremenljivko željenega tipa z operatorjem <literal>new</literal>. </para> <informalexample> @@ -137,41 +134,38 @@ </informalexample> <para> - This creates the objects $cart and $another_cart, both of - the class Cart. The function add_item() of the $cart object - is being called to add 1 item of article number 10 to the - $cart. 3 items of article number 0815 are being added to - $another_cart. + To ustvari objekta $cart in $another_cart, oba razreda Cart. Funkcija + add_item() $cart objekta je klicana za dodajanje enega predmeta, ki ima + številko artikla 10, v objekt $cart. Trije predmeti, ki imajo številko + artikla 0815 so dodani v $another_cart. </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 ->. - Thus, the names $cart->items and $another_cart->items - name two different variables. Note that the variable is - named $cart->items, not $cart->$items, that is, a - variable name in PHP has only a single dollar sign. + Oba objekta, $cart in $another_cart imata funkciji add_item(), + remove_item in spremenljivke. To so različne funkcije in + spremenljivke. Objekte si lahko predstavljate kot direktorije v + datotečnem sistemu. V datotečnem sistemu imate lahko dve + različ:ni datoteki README.TXT dokler sta ti dve datoteki vsaka v + svojem direktoriju. Tako kot pri direktorijih, kjer morate vpisati celotno + pot iz vrhovnega direktorija, morate tu uporabiti celotno ime funkcije ki jo + želite klicati. V PHP-ju bi bil vrhovni direktorij globalni imenski + prostor in ločilec za direktorije ->. + Tako so imena $vart->items in $another_cart->items + imena za dve različni spremenljivki. Zapomnite si da je spremenljivka + imenovana $vart->items in ne $cart->$items. To poemni, da ima + spremenljivka v PHP-ju samo en dolar znak. </para> <informalexample> <programlisting role="php"> <![CDATA[ -// correct, single $ +// pravilno, enojni $ $cart->items = array("10" => 1); -// invalid, because $cart->$items becomes $cart->"" +// napacno, ker $cart->$items postane $cart->"" $cart->$items = array("10" => 1); -// correct, but may or may not be what was intended: +// pravilno, ce je to kar ste zeleli: // $cart->$myvar becomes $cart->items $myvar = 'items'; $cart->$myvar = array("10" => 1); @@ -180,24 +174,21 @@ </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->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'. + V definiciji razreda nevemo pod kaksnim imenom bo objekt dostopen v nasem programu: + v trenutku, ko smo pisali razred Cart, ime objekta #cart ali $another_cart + ni bilo zmano. Torej ne morate pisati $cart->items v samem Cart razredu. + Namesto tega, če želimo dostopati do funkcij in spremenljivk + razreda v razredu samem, uporabimo izmišljeno spremenljivko $this, ki si + jo lahko predstavljamo kot 'moje' ali 'trenutni objekt'. Torej bi + '$this->items[$artnr] += $num' lahko prebrali kot 'dodaj $num k $artnr + števcu v moji tabeli predmetov' ali 'dodaj $num k $artnr števcu + v tabeli predmetov v trenutnem objektu'. </para> <note> <para> - There are some nice functions to handle classes and objects. You might want - to take a look at the <link linkend="ref.classobj">Class/Object - Functions</link> + Obstaja kar nekaj zanimivh funkcij za upravljanje razredov in objektov. Oglejte + si <link linkend="ref.classobj">Razredne/Objektne Funkcije</link> </para> </note> </sect1> @@ -206,19 +197,18 @@ <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'. + Velikokrat potrebujete razrede s podobnimi spremenljivkami in + funkcijami v drugem obstoječem razredu. Pravzaprav je dobra + praksa definirati splošni razred, ki ga lahko uporabite v vseh + vaših projektih in ga prilagajate vsakemu vašemu + specifičnem projektu. Da si olajšate to delo, so razredi + lahko razširitev drugih razredov. Razširjen ali izpeljan + razred ima vse funkcije in spremenljivke osnovnega razreda + (temu rešemo 'podedovanje', šeprav ni nihše umrl) in + kar mu dodate v extends definiciji. Odstranjevanje funkcij ali + spremenljivk ni možno, torej da bi izbrisali kaksno obstoječo + funkcijo ali spremenljivko. Razširjeni razred je vedno odvisen od + osnovnega razreda. Razredi so razširjeni z uporabo 'extends'. </para> <informalexample> @@ -238,20 +228,20 @@ </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: + Zgornje definira razred Named_Cart, ki ima vse spremenljivke in + funkcije razreda Cart in dodatno spremenljivko $owner in dodatno + funkcijo set_owner(). 'Named cart' ustvarite normalno in lahko + sedaj nastavite ali dobite vrednost $owner. Seveda lahko uporabite vse + funkcije in spremenljivke Cart razreda: </para> <informalexample> <programlisting role="php"> <![CDATA[ -$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) +$ncart = new Named_Cart; // Ustvari objekt Named_Cart razreda +$ncart->set_owner("kris"); // Uporabimo fukcijo v Named_Cart razredu +print $ncart->owner; // Uporabimo spremenljivko v Named_Cart razredu +$ncart->add_item("10", 1); // (podedovana funkcionalnost iz Cart razreda) ]]> </programlisting> </informalexample>