cvs: phpdoc-sl /language oop.xml
| From: | Dejan Markic | Date: | Sun, 19 Jan 2003 21:11:23 +0000 |
| Subject: | cvs: phpdoc-sl /language oop.xml | ||
| Groups: | php.doc.sl | ||
| Request: | Send a blank email to doc-sl+get-44@lists.php.net to get a copy of this message | ||
dejan Sun Jan 19 16:11:23 2003 EDT
Modified files:
/phpdoc-sl/language oop.xml
Log:
This is looong ..
Index: phpdoc-sl/language/oop.xml diff -u phpdoc-sl/language/oop.xml:1.2 phpdoc-sl/language/oop.xml:1.3 --- phpdoc-sl/language/oop.xml:1.2 Sun Jan 12 15:45:49 2003 +++ phpdoc-sl/language/oop.xml Sun Jan 19 16:11:22 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> <!-- $EN-Revision: 1.36 Maintainer: dejan Status: working --> <chapter id="language.oop"> <title>Razredi in objekti</title> @@ -8,7 +8,7 @@ <title><literal>razred</literal></title> <para> Razred je zbirka spremenljivk in funkcij, ki delajo s temi spremenljivkami. - razred definiramo z naslednjo sintakso: + Razred definiramo z naslednjo sintakso: <informalexample> <programlisting role="php"> @@ -62,9 +62,9 @@ <simpara> 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. + 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> @@ -136,23 +136,23 @@ <para> 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 + številko artikla 10, v objektu $cart. Trije predmeti, ki imajo številko artikla 0815 so dodani v $another_cart. </para> <para> Oba objekta, $cart in $another_cart imata funkciji add_item(), - remove_item in spremenljivke. To so različne funkcije in + 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 + 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 + Tako so imena $var->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 + imenovana $cart->items in ne $cart->$items. To poemni, da ima spremenljivka v PHP-ju samo en dolar znak. </para> @@ -174,8 +174,8 @@ </informalexample> <para> - 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 + V definiciji razreda nevemo pod kaksnim imenom bo objekt dostopen v našem 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 @@ -229,7 +229,7 @@ <para> Zgornje definira razred Named_Cart, ki ima vse spremenljivke in - funkcije razreda Cart in dodatno spremenljivko $owner in dodatno + funkcije razreda Cart, 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: @@ -247,50 +247,47 @@ </informalexample> <para> - This is also called a "parent-child" relationship. You create a class, - parent, and use <literal>extends</literal> to create a new class - <emphasis>based</emphasis> on the parent class: the child class. You can - even use this new child class and create another class based on this child - class. + Temu pravimo "parent-child" zveza. Vi ustvarite razred, parent + in uporabite <literal>extends</literal> da ustvarite nov razred, ki + <emphasis>temelji</emphasis> na parent razredu: child razred. Child razred + lahko uporabite tudi za ustvarjanje novega razreda, ki temelji na tem + child razredu. </para> <note> <para> - Classes must be defined before they are used! If you want the class - <literal>Named_Cart</literal> to extend the class - <literal>Cart</literal>, you will have to define the class - <literal>Cart</literal> first. If you want to create another class called - <literal>Yellow_named_cart</literal> based on the class - <literal>Named_Cart</literal> you have to define - <literal>Named_Cart</literal> first. To make it short: the order in which - the classes are defined is important. + Razredi morajo biti definirani pred uporabo! Če želite da razred + <literal>Named_Cart</literal> podeduje razred <literal>Cart</literal>, boste + morali prvo definirati razred <literal>Cart</literal>. Če želite + ustvariti še <literal>Yellow_named_cart</literal> razred, ki temelji na + <literal>Named_Cart</literal> razredu, boste morali prvo definirati + <literal>Named_Cart</literal> razred. Na kratko: vrstni red definiranja razredov + je pomemben. </para> </note> </sect1> <sect1 id="language.oop.constructor"> - <title><literal>Constructors</literal></title> + <title><literal>Konstruktorji</literal></title> <caution> <simpara> - In PHP 3 and PHP 4 constructors behave differently. The PHP 4 - semantics are strongly preferred. + Obnašanje konstruktorjev v PHP 3 in PHP 4 je različno. + Obnašanje v PHP 4 je seveda boljše. </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). + Konstruktorji so funkcije v razredu, ki so klicate avtomatsko ko + ustvarite novo instanco razreda z <literal>new</literal>. V PHP 3 + funkcija postane konstruktor, ko ima isto ime kot razred. V PHP 4 + funkcija postane konstruktor, ko ima isto ime kot razred v katerem je + definirana - razlika je majhna a pomembna. </para> <informalexample> <programlisting role="php"> <![CDATA[ -// Works in PHP 3 and PHP 4. +// Dela v PHP 3 in PHP 4. class Auto_Cart extends Cart { function Auto_Cart() @@ -303,19 +300,18 @@ </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. + Zgornja koda definira razred Auto_Cart, torej Cart in konstruktor, + ki inicializira Cart z novim predmeto, ki ima številko artikla + "10", vsakič ko ga ustvarimo z "new". Konstruktorji imajo lahko + tudi argumente, kar jim seveda poveča uporabnost. Da bi lahko + uporabili razred brez parametrov, definiramo argumente kot neobvezne z + definiranjem privzetih vrednosti. </para> <informalexample> <programlisting role="php"> <![CDATA[ -// Works in PHP 3 and PHP 4. +// Dela v PHP 3 in PHP 4. class Constructor_Cart extends Cart { function Constructor_Cart($item = "10", $num = 1) @@ -324,11 +320,11 @@ } } -// Shop the same old boring stuff. +// Tukaj dobi privzete vrednosti. $default_cart = new Constructor_Cart; -// Shop for real... +// Tukaj podamo argumente konstruktorju $different_cart = new Constructor_Cart("20", 17); ]]> @@ -336,16 +332,15 @@ </informalexample> <para> - You also can use the <literal>@</literal> operator to - <emphasis>mute</emphasis> errors occuring in the constructor, e.g. - <literal>@new</literal>. + Uporabite lahko tudi <literal>@</literal> operator, da + preprečite izpisovanje morebitnih napak v konstruktorju, + recimo <literal>@new</literal>. </para> <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. + V PHP 3 imajo izpeljani razredi in konstruktorji veliko omejitev. + Za boljše razumevanje si pazljivo preberite naslednje primere. </simpara> </caution> @@ -356,7 +351,7 @@ { function A() { - echo "I am the constructor of A.<br>\n"; + echo "Jaz sem konstruktor razreda A.<br>\n"; } } @@ -364,28 +359,28 @@ { function C() { - echo "I am a regular function.<br>\n"; + echo "Jaz sem navadna funkcija.<br>\n"; } } -// no constructor is being called in PHP 3. +// V PHP 3 se konstruktor ne bo klical $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. + V PHP 3 se konstruktor ne bo klical v zgornjem primeru. Pravilo + v PHP 3 je: 'Konstruktor je funkcija, ki ima isto ime kot razred.'. + Razred ima ime B in v tem razredu ni nobene funkcije z imenom B(). + Nič se ne zgodi. </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.<br>' in PHP 4. + To je popravljeno v PHP 4 z novim pravilom: Če razred nima + konstruktorja, kličemo konstrukor osnovnega razreda, če + obstaja. Zgornji primer bi izpisal: 'Jaz sem konstruktor razreda A.<br>' + v PHP 4. </para> <informalexample> @@ -395,13 +390,13 @@ { function A() { - echo "I am the constructor of A.<br>\n"; + echo "Jaz sem konstruktor razreda A.<br>\n"; } function B() { - echo "I am a regular function named B in class A.<br>\n"; - echo "I am not a constructor in A.<br>\n"; + echo "Jaz sem navadna funkcija B v razredu A.<br>\n"; + echo "Jaz nisem konstruktor v razredu A.<br>\n"; } } @@ -409,54 +404,50 @@ { function C() { - echo "I am a regular function.<br>\n"; + echo "Jaz sem navadna funkcija.<br>\n"; } } -// This will call B() as a constructor. +// To bo klicalo B() kot 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. + V PHP 3 bo funkcija B() v razredu A postala konstruktor v razredu + B, čeprav tega nismo želeli. Pravilo v PHP 3 pravi: 'Konstruktor + je funkcija, katere ime je enako imenu razreda.'. PHP 3 ne zanima ali je + funkcija definirana v razredu B ali pa je bila podedovana. </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.<br>'. + To je popravljeno v PHP 4 z spremembno tega pravila v: 'Konstruktor + je funkcija, ki ima isto ime kot razred v katerem je definirana.'. Torej v + PHP 4, razred B nebi imel konstruktorja in bi klicali konstruktor osnovnega + razreda, kar bi izpisalo: 'Jat sem konstruktor razreda A.<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. + Tako PHP 3 kot PHP 4 ne bosta klicala konstruktorja osnovnega razreda + avtomatično iz konstruktorja izpeljanega razreda. Vaša naloga + je, da kličete konstruktorje osnovnih razredov kjer to želite. </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. + Destruktorji ne obstajajo v PHP 3 ali PHP 4. Uporabite + lahko funkcijo <function>register_shutdown_function</function>, + s katero simulirate efekt destruktorjev. </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. + Destruktorji so funkcije, ki so klicane avtomatsko, ko uničimo + razred z funkcijo <function>unset</funtion> ali ko gremo ven iz območja. + Konstruktorji ne obstajajo v PHP. </para> </sect1> @@ -465,15 +456,14 @@ <caution> <simpara> - The following is valid for PHP 4 only. + Naslednje je veljavno samo v 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. + Včasih je uporabno uporabljati funkcije in sprememnljivke v + osnovnem razredu ali uporabljati funkcije v razredih, ki se nimajo + instance. Za to uporabljamo :: operator. </para> <informalexample> @@ -483,7 +473,7 @@ { function example() { - echo "I am the original function A::example().<br>\n"; + echo "Jaz sem funkcija A::example().<br>\n"; } } @@ -491,58 +481,54 @@ { function example() { - echo "I am the redefined function B::example().<br>\n"; + echo "Jaz sem redefinirana funkcija B::example().<br>\n"; A::example(); } } -// there is no object of class A. -// this will print -// I am the original function A::example().<br> +// objekt razreda A ne obstaja. +// Izpis +// Jaz sem funkcija A::example().<br> A::example(); -// create an object of class B. +// naredimo objekt razreda B. $b = new B; -// this will print -// I am the redefined function B::example().<br> -// I am the original function A::example().<br> +// izpis +// Jaz sem redefinirana funkcija B::example().<br> +// Jaz sem funkcija A::example().<br> $b->example(); ]]> </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. + Zgornji primer kliče funkcijo expample() v razredu A, + ampak objekt razreda A ne obstaja, torej ne moremo napisati + $a->example() ali podobno. Namesto tega, kličemo + funkcijo example()= kot 'razredno funkcijo', torej kot funkcijo + samega razreda in ne objekta tega razreda. </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. + Obstajajo razredne funkcije, a ne obstajajo razredne spremenljivke. + Dejstvo je, da med klicom objekta ni. Torej razredna funkcija ne sme + uporabljati objektnih spremenljivk (lahko uporablja lokalne in globalne + spremenljivke) in seveda ne sme uporabljati $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). + V zgornjem primeru, razred B redefinira funkcijo example(). Originalna + definicija v razredu A je uničena in ni več na voljo, razen če + specificirate implementacijo funkcije example() v razredu A z operatorjem ::. + Napišite A::example() da to naredite (pravzaprav bi morali pisati + parent::example(), kot je prikazano v naslednjem primeru). </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. + V tem kontekstu, obstaja trenutni objekt in ima lahko + objektne spremenljivke. Torej, ko je uporabljen ZNOTRAJ + objektne funkcije, lahko uporabimo $this in objektne spremenljivke. </para> </sect1>
Index: phpdoc-sl/language/oop.xml diff -u phpdoc-sl/language/oop.xml:1.2 phpdoc-sl/language/oop.xml:1.3 --- phpdoc-sl/language/oop.xml:1.2 Sun Jan 12 15:45:49 2003 +++ phpdoc-sl/language/oop.xml Sun Jan 19 16:11:22 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> <!-- $EN-Revision: 1.36 Maintainer: dejan Status: working --> <chapter id="language.oop"> <title>Razredi in objekti</title> @@ -8,7 +8,7 @@ <title><literal>razred</literal></title> <para> Razred je zbirka spremenljivk in funkcij, ki delajo s temi spremenljivkami. - razred definiramo z naslednjo sintakso: + Razred definiramo z naslednjo sintakso: <informalexample> <programlisting role="php"> @@ -62,9 +62,9 @@ <simpara> 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. + 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> @@ -136,23 +136,23 @@ <para> 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 + številko artikla 10, v objektu $cart. Trije predmeti, ki imajo številko artikla 0815 so dodani v $another_cart. </para> <para> Oba objekta, $cart in $another_cart imata funkciji add_item(), - remove_item in spremenljivke. To so različne funkcije in + 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 + 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 + Tako so imena $var->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 + imenovana $cart->items in ne $cart->$items. To poemni, da ima spremenljivka v PHP-ju samo en dolar znak. </para> @@ -174,8 +174,8 @@ </informalexample> <para> - 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 + V definiciji razreda nevemo pod kaksnim imenom bo objekt dostopen v našem 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 @@ -229,7 +229,7 @@ <para> Zgornje definira razred Named_Cart, ki ima vse spremenljivke in - funkcije razreda Cart in dodatno spremenljivko $owner in dodatno + funkcije razreda Cart, 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: @@ -247,50 +247,47 @@ </informalexample> <para> - This is also called a "parent-child" relationship. You create a class, - parent, and use <literal>extends</literal> to create a new class - <emphasis>based</emphasis> on the parent class: the child class. You can - even use this new child class and create another class based on this child - class. + Temu pravimo "parent-child" zveza. Vi ustvarite razred, parent + in uporabite <literal>extends</literal> da ustvarite nov razred, ki + <emphasis>temelji</emphasis> na parent razredu: child razred. Child razred + lahko uporabite tudi za ustvarjanje novega razreda, ki temelji na tem + child razredu. </para> <note> <para> - Classes must be defined before they are used! If you want the class - <literal>Named_Cart</literal> to extend the class - <literal>Cart</literal>, you will have to define the class - <literal>Cart</literal> first. If you want to create another class called - <literal>Yellow_named_cart</literal> based on the class - <literal>Named_Cart</literal> you have to define - <literal>Named_Cart</literal> first. To make it short: the order in which - the classes are defined is important. + Razredi morajo biti definirani pred uporabo! Če želite da razred + <literal>Named_Cart</literal> podeduje razred <literal>Cart</literal>, boste + morali prvo definirati razred <literal>Cart</literal>. Če želite + ustvariti še <literal>Yellow_named_cart</literal> razred, ki temelji na + <literal>Named_Cart</literal> razredu, boste morali prvo definirati + <literal>Named_Cart</literal> razred. Na kratko: vrstni red definiranja razredov + je pomemben. </para> </note> </sect1> <sect1 id="language.oop.constructor"> - <title><literal>Constructors</literal></title> + <title><literal>Konstruktorji</literal></title> <caution> <simpara> - In PHP 3 and PHP 4 constructors behave differently. The PHP 4 - semantics are strongly preferred. + Obnašanje konstruktorjev v PHP 3 in PHP 4 je različno. + Obnašanje v PHP 4 je seveda boljše. </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). + Konstruktorji so funkcije v razredu, ki so klicate avtomatsko ko + ustvarite novo instanco razreda z <literal>new</literal>. V PHP 3 + funkcija postane konstruktor, ko ima isto ime kot razred. V PHP 4 + funkcija postane konstruktor, ko ima isto ime kot razred v katerem je + definirana - razlika je majhna a pomembna. </para> <informalexample> <programlisting role="php"> <![CDATA[ -// Works in PHP 3 and PHP 4. +// Dela v PHP 3 in PHP 4. class Auto_Cart extends Cart { function Auto_Cart() @@ -303,19 +300,18 @@ </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. + Zgornja koda definira razred Auto_Cart, torej Cart in konstruktor, + ki inicializira Cart z novim predmeto, ki ima številko artikla + "10", vsakič ko ga ustvarimo z "new". Konstruktorji imajo lahko + tudi argumente, kar jim seveda poveča uporabnost. Da bi lahko + uporabili razred brez parametrov, definiramo argumente kot neobvezne z + definiranjem privzetih vrednosti. </para> <informalexample> <programlisting role="php"> <![CDATA[ -// Works in PHP 3 and PHP 4. +// Dela v PHP 3 in PHP 4. class Constructor_Cart extends Cart { function Constructor_Cart($item = "10", $num = 1) @@ -324,11 +320,11 @@ } } -// Shop the same old boring stuff. +// Tukaj dobi privzete vrednosti. $default_cart = new Constructor_Cart; -// Shop for real... +// Tukaj podamo argumente konstruktorju $different_cart = new Constructor_Cart("20", 17); ]]> @@ -336,16 +332,15 @@ </informalexample> <para> - You also can use the <literal>@</literal> operator to - <emphasis>mute</emphasis> errors occuring in the constructor, e.g. - <literal>@new</literal>. + Uporabite lahko tudi <literal>@</literal> operator, da + preprečite izpisovanje morebitnih napak v konstruktorju, + recimo <literal>@new</literal>. </para> <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. + V PHP 3 imajo izpeljani razredi in konstruktorji veliko omejitev. + Za boljše razumevanje si pazljivo preberite naslednje primere. </simpara> </caution> @@ -356,7 +351,7 @@ { function A() { - echo "I am the constructor of A.<br>\n"; + echo "Jaz sem konstruktor razreda A.<br>\n"; } } @@ -364,28 +359,28 @@ { function C() { - echo "I am a regular function.<br>\n"; + echo "Jaz sem navadna funkcija.<br>\n"; } } -// no constructor is being called in PHP 3. +// V PHP 3 se konstruktor ne bo klical $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. + V PHP 3 se konstruktor ne bo klical v zgornjem primeru. Pravilo + v PHP 3 je: 'Konstruktor je funkcija, ki ima isto ime kot razred.'. + Razred ima ime B in v tem razredu ni nobene funkcije z imenom B(). + Nič se ne zgodi. </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.<br>' in PHP 4. + To je popravljeno v PHP 4 z novim pravilom: Če razred nima + konstruktorja, kličemo konstrukor osnovnega razreda, če + obstaja. Zgornji primer bi izpisal: 'Jaz sem konstruktor razreda A.<br>' + v PHP 4. </para> <informalexample> @@ -395,13 +390,13 @@ { function A() { - echo "I am the constructor of A.<br>\n"; + echo "Jaz sem konstruktor razreda A.<br>\n"; } function B() { - echo "I am a regular function named B in class A.<br>\n"; - echo "I am not a constructor in A.<br>\n"; + echo "Jaz sem navadna funkcija B v razredu A.<br>\n"; + echo "Jaz nisem konstruktor v razredu A.<br>\n"; } } @@ -409,54 +404,50 @@ { function C() { - echo "I am a regular function.<br>\n"; + echo "Jaz sem navadna funkcija.<br>\n"; } } -// This will call B() as a constructor. +// To bo klicalo B() kot 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. + V PHP 3 bo funkcija B() v razredu A postala konstruktor v razredu + B, čeprav tega nismo želeli. Pravilo v PHP 3 pravi: 'Konstruktor + je funkcija, katere ime je enako imenu razreda.'. PHP 3 ne zanima ali je + funkcija definirana v razredu B ali pa je bila podedovana. </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.<br>'. + To je popravljeno v PHP 4 z spremembno tega pravila v: 'Konstruktor + je funkcija, ki ima isto ime kot razred v katerem je definirana.'. Torej v + PHP 4, razred B nebi imel konstruktorja in bi klicali konstruktor osnovnega + razreda, kar bi izpisalo: 'Jat sem konstruktor razreda A.<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. + Tako PHP 3 kot PHP 4 ne bosta klicala konstruktorja osnovnega razreda + avtomatično iz konstruktorja izpeljanega razreda. Vaša naloga + je, da kličete konstruktorje osnovnih razredov kjer to želite. </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. + Destruktorji ne obstajajo v PHP 3 ali PHP 4. Uporabite + lahko funkcijo <function>register_shutdown_function</function>, + s katero simulirate efekt destruktorjev. </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. + Destruktorji so funkcije, ki so klicane avtomatsko, ko uničimo + razred z funkcijo <function>unset</funtion> ali ko gremo ven iz območja. + Konstruktorji ne obstajajo v PHP. </para> </sect1> @@ -465,15 +456,14 @@ <caution> <simpara> - The following is valid for PHP 4 only. + Naslednje je veljavno samo v 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. + Včasih je uporabno uporabljati funkcije in sprememnljivke v + osnovnem razredu ali uporabljati funkcije v razredih, ki se nimajo + instance. Za to uporabljamo :: operator. </para> <informalexample> @@ -483,7 +473,7 @@ { function example() { - echo "I am the original function A::example().<br>\n"; + echo "Jaz sem funkcija A::example().<br>\n"; } } @@ -491,58 +481,54 @@ { function example() { - echo "I am the redefined function B::example().<br>\n"; + echo "Jaz sem redefinirana funkcija B::example().<br>\n"; A::example(); } } -// there is no object of class A. -// this will print -// I am the original function A::example().<br> +// objekt razreda A ne obstaja. +// Izpis +// Jaz sem funkcija A::example().<br> A::example(); -// create an object of class B. +// naredimo objekt razreda B. $b = new B; -// this will print -// I am the redefined function B::example().<br> -// I am the original function A::example().<br> +// izpis +// Jaz sem redefinirana funkcija B::example().<br> +// Jaz sem funkcija A::example().<br> $b->example(); ]]> </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. + Zgornji primer kliče funkcijo expample() v razredu A, + ampak objekt razreda A ne obstaja, torej ne moremo napisati + $a->example() ali podobno. Namesto tega, kličemo + funkcijo example()= kot 'razredno funkcijo', torej kot funkcijo + samega razreda in ne objekta tega razreda. </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. + Obstajajo razredne funkcije, a ne obstajajo razredne spremenljivke. + Dejstvo je, da med klicom objekta ni. Torej razredna funkcija ne sme + uporabljati objektnih spremenljivk (lahko uporablja lokalne in globalne + spremenljivke) in seveda ne sme uporabljati $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). + V zgornjem primeru, razred B redefinira funkcijo example(). Originalna + definicija v razredu A je uničena in ni več na voljo, razen če + specificirate implementacijo funkcije example() v razredu A z operatorjem ::. + Napišite A::example() da to naredite (pravzaprav bi morali pisati + parent::example(), kot je prikazano v naslednjem primeru). </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. + V tem kontekstu, obstaja trenutni objekt in ima lahko + objektne spremenljivke. Torej, ko je uporabljen ZNOTRAJ + objektne funkcije, lahko uporabimo $this in objektne spremenljivke. </para> </sect1>