cvs: phpdoc /hu/language oop.xml

From: Date: Sun, 29 Oct 2000 16:22:11 +0000
Subject: cvs: phpdoc /hu/language oop.xml
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969332715@lists.php.net to get a copy of this message
goba Sun Oct 29 08:22:11 2000 EDT Modified files: /phpdoc/hu/language oop.xml Log: A new file :)

Index: phpdoc/hu/language/oop.xml diff -u phpdoc/hu/language/oop.xml:1.1 phpdoc/hu/language/oop.xml:1.2 --- phpdoc/hu/language/oop.xml:1.1 Wed Aug 9 08:03:31 2000 +++ phpdoc/hu/language/oop.xml Sun Oct 29 08:22:11 2000 @@ -1,29 +1,30 @@ <chapter id="language.oop"> - <title>Osztályok és objektumok</title> + <title>Osztályok, objektumok</title> <sect1 id="keyword.class"> <title><literal>class</literal></title> <para> - A class is a collection of variables and functions working with - these variables. A class is defined using the following syntax: - + Az osztály (objektumtípus) változók és rajtuk mûveletet végzõ + függvények [metódusok] együttese. Osztályt az alábbi szintakszis szerint lehet + definiálni: <informalexample> <programlisting role="php"> -&lt;?php -class Cart { - var $items; // Items in our shopping cart +<![CDATA[ +<?php +class Kosar { + var $dolgok; // A kosárban levõ dolgok - // Add $num articles of $artnr to the cart + // berak a kosárba $db darabot az $sorsz indexû dologból - function add_item ($artnr, $num) { - $this->items[$artnr] += $num; + function berak ($sorsz, $db) { + $this->dolgok[$sorsz] += $db; } - // Take $num articles of $artnr out of the cart + // kivesz a kosárból $db darabot az $sorsz indexû dologból - function remove_item ($artnr, $num) { - if ($this->items[$artnr] > $num) { - $this->items[$artnr] -= $num; + function kivesz ($sorsz, $db) { + if ($this->items[$sorsz] > $db) { + $this->items[$sorsz] -= $db; return true; } else { return false; @@ -31,119 +32,141 @@ } } ?> +]]> </programlisting> </informalexample> </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. - </para> + Ez definiál egy Kosar nevû osztályt, ami a kosárban levõ áruk + asszociatív tömbjébõl áll, és definiál 2 funkciót hozzá, hogy + bele lehessen rakni, illetve kivenni a kosárból. + </para> + <note><simpara> + PHP 4-ben csak konstans <literal>var</literal> inicializáló + értékek megengedettek. Használd a konstruktort nem konstans + értékû inicializáláshoz. + </simpara></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 new operator. + Az osztályok típusok, vagyis az aktuális változók tervrajzai. + A kívánt típusú változót a new operátorral hozhatod létre. </para> <informalexample> <programlisting role="php"> - $cart = new Cart; - $cart->add_item("10", 1); + <![CDATA[ + $kosar = new Kosar; + $kosar->berak("10", 1); + ]]> </programlisting> </informalexample> + <para> + Ez létrehozza a Kosar objektumosztály $kosar nevû objektumpéldányát. + Az objektum berak() függvényét meghívtuk, hogy a 10-es számú árucikkbõl + rakjon 1 darabot a kosárba. + </para> <para> - This creates an object $cart of the class Cart. The function - add_item() of that object is being called to add 1 item of article - number 10 to the cart. </para><para> Classes can be extensions of - other classes. The extended or derived class has all variables and - functions of the base class and what you add in the extended - definition. This is done using the extends keyword. Multiple - inheritance is not supported. + Osztályok származhatnak más osztályoktól is (öröklés). + A leszármazott osztály az õs minden változóját és függvényét + [metódusát] örökli. Erre használható az extends kulcsszó. + A többszörös öröklés nem támogatott [:( vagyis egy gyereknek több õst nem + nevezhetünk meg. A tranzitív öröklés azonban megengedett]. </para> <informalexample> <programlisting role="php"> -class Named_Cart extends Cart { - var $owner; +<![CDATA[ +class Gazdas_Kosar extends Kosar { + var $tulaj; - function set_owner ($name) { - $this->owner = $name; + function tulajdonosa ($nev) { + $this->tulaj = $nev; } } +]]> </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: + Ez definiál egy Gazdas_Kosar nevû osztályt, ami a Kosar összes + változójával és metódusával rendelkezik, és van egy saját változója, + a $tulaj, no meg egy saját metódusa, a tulajdonosa(). + A gazdás kosarat a hagyományos módon hozhatod létre, és a kosár + tulajdonosát is be tudod állítani, le tudod kérdezni [ebben + az esetben favágó módszerrel]. A gazdás kosarakon továbbra is + lehet használni a Kosar függvényeit: </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) +<![CDATA[ +$gkosar = new Gazdas_Kosar; // Gazdás kosár létrehozása +$gkosar->tulajdonosa ("Namilesz Teosztasz"); // a tulaj beállítása +print $gkosar->tulaj; // a tulajdonos neve +$gkosar->break ("10", 1); // (Kosar-ból öröklött funkcionalitás) +]]> </programlisting> </informalexample> <para> - Within functions of a class the variable $this means this - object. You have to use $this->something to access any variable or - function named something within your current object. + Osztályok függvényein belül a $this a manipulálandó objektumpéldányt jelenti. + A $this->valami formát kell használnod az aktuális objektum valami nevû + változó vagy metódus elérésére. </para> <para> - Constructors are functions in a class that are automatically - called when you create a new instance of a class. A function - becomes a constructor when it has the same name as the class. + A konstruktorok olyan az osztályok olyan metódusai, amelyek + automatikusan meghívódnak, amikor létrehozol egy új objektumpéldányt. + Egy függvény [metódus] úgy lesz konstruktor, ha a neve megegyezik + az osztály nevével. </para> <informalexample> <programlisting role="php"> -class Auto_Cart extends Cart { - function Auto_Cart () { - $this->add_item ("10", 1); +<![CDATA[ +class Auto_Kosar extends Kosar { + function Auto_Kosar () { + $this->berak ("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 also take arguments and these arguments can be optional, which - makes them much more useful. + Ez egy olyan Auto_Kosar nevû osztályt [objektumtípust] hoz létre, + mint a Kosar, csak rendelkezik egy konstruktorral, ami inicializálja + a kosarat 1 darab "10"-es áruval, valahányszor a new operátorral + hozzuk létre az objektumot. [de csak akkor!!!] A konstruktoroknak + is lehetnek paramétereik, és ezek lehetnek opcionálisak, ami még + hasznosabbá teszi õket. </para> <informalexample> <programlisting role="php"> -class Constructor_Cart extends Cart { - function Constructor_Cart ($item = "10", $num = 1) { - $this->add_item ($item, $num); +<![CDATA[ +class Konstruktoros_Kosar extends Kosar { + function Konstruktoros_Kosar ($sorsz = "10", $db = 1) { + $this->berak ($sorsz, $db); } } -// Shop the same old boring stuff. +// Mindig ugyanazt az uncsi dolgot veszi... -$default_cart = new Constructor_Cart; +$kiindulo_kosar = new Konstruktoros_Kosar; -// Shop for real... +// Igazi vásárlás -$different_cart = new Constructor_Cart ("20", 17); +$masik_kosar = new Konstruktoros_kosar ("20", 17); +]]> </programlisting> </informalexample> <caution> <simpara> - For derived classes, the constructor of the parent class is not - automatically called when the derived class's constructor is - called. + A leszármaztatott osztályokban a szülõ osztály konstruktora + <emphasis>NEM</emphasis> hívódik meg automatikusan, amikor + a származtatott osztály konstruktorát meghívod. </simpara> </caution> </sect1>
« previous php.doc (#969332715) next »