tom Thu Mar 28 15:44:54 2002 EDT Modified files: /phpdoc/de/language oop.xml Log: first part translated
Index: phpdoc/de/language/oop.xml diff -u phpdoc/de/language/oop.xml:1.8 phpdoc/de/language/oop.xml:1.9 --- phpdoc/de/language/oop.xml:1.8 Wed Mar 27 14:22:06 2002 +++ phpdoc/de/language/oop.xml Thu Mar 28 15:44:54 2002 @@ -1,30 +1,30 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.8 $ --> +<!-- EN-Revision: 1.32 Maintainer: tom Status: working --> <chapter id="language.oop"> - <title>Classes and Objects</title> + <title>Klassen und Objekte</title> <sect1 id="keyword.class"> - <title><literal>class</literal></title> + <title><literal>Klassen</literal></title> <para> - A class is a collection of variables and functions working with - these variables. A class is defined using the following syntax: - + Eine Klasse ist eine Sammlung von Variablen und Funktionen, die + mit diesen Variablen arbeiten. Eine Klasse wird folgendermaßen + definiert: <informalexample> <programlisting role="php"> <![CDATA[ <?php class Cart { - var $items; // Items in our shopping cart + var $items; // Artikel in unserem Einkaufswagen - // Add $num articles of $artnr to the cart + // Füge dem Einkaufswagen $num Artikel der Sorte $artnr zu function add_item ($artnr, $num) { $this->items[$artnr] += $num; } - // Take $num articles of $artnr out of the cart + // Nimm $num Artikel von $artnr aus dem Einkaufswagen function remove_item ($artnr, $num) { @@ -43,50 +43,53 @@ </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. + In diesem Beispiel wird eine Klasse "Cart" definiert. Sie + besteht aus einem assoziativen Array von Produkten im + Einkaufswagen und zwei Funktionen zum Hinzufügen und Entfernen von + Artikeln. </para> <caution> <simpara> - The following cautionary notes are valid for PHP 4. + Die folgenden warnenden Bemerkungen gelten für 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. + Der Name <literal>stdClass</literal> ist reserviert, da er intern + von Zend benutzt wird. Sie können in PHP keine Klasse mit dem + Namen <literal>stdClass</literal> haben. </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. + Die Funktionsnamen <literal>__sleep</literal> und + <literal>__wakeup</literal> sind in PHP Klassen "magisch". Sie + können in Ihren Klassen keine Funktionen mit diesen Namen haben, + außer Sie wollen sie mit dieser "magischen" Funktionalität + assoziieren. Mehr Informationen dazu finden Sie weiter unten. </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. + Sämtliche mit __ beginnende Funktionsnamen PHP als "magisch" + vorbehalten. Es wird empfohlen, in PHP keine Funktionsnamen mit + __ zu verwenden, außer Sie möchten dokumentierte "magische" + Funktionalität. </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). + In PHP 4 sind nur konstante Initialisierungen für + <literal>var</literal> Variablen erlaubt. Um Variablen mit nicht + konstanten Werten zu initialisieren, benötigen Sie eine Funktion + zur Intitialisierung, welche beim Erstellen eines Objektes + automatisch von der Klasse aufgerufen wird. Eine solche Funktion + wird Konstruktor genannt (siehe unten). </simpara> <informalexample> <programlisting role="php"> <![CDATA[ <?php -/* None of these will work in PHP 4. */ +/* Keine wird in PHP 4 funktionieren */ class Cart { var $todays_date = date("Y-m-d"); @@ -95,7 +98,7 @@ var $items = array("VCR", "TV"); } -/* This is how it should be done. */ +/* So sollte es gemacht werden */ class Cart { var $todays_date; @@ -116,9 +119,9 @@ </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. + Klassen sind Typen, das heißt sie sind die Blaupausen für reale + Variablen. Um sie zu nutzen, muss zunächst eine Variable mit dem + Operator <literal>new</literal> angelegt werden. </para> <informalexample> @@ -135,42 +138,42 @@ </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. + Dies erstellt die Objekte $cart und $another_cart aus der Klasse + Cart. Dann wird die Funktion add_item() des $cart Objektes + aufgerufen, um $cart einen Artikel mit der Artikelnummer 10 + hinzuzufügen. 3 Artikel mit der Artikelnummer 0815 werden + $another_cart hinzugefügt. </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. + Sowohl $cart als auch $another_cart haben die Funktionen + add_item(), remove_item() und die Variable items. Dies sind + verschiedene Funktionen und Variablen. Sie können sich Objekte + ähnlich den Verzeichnissen in einem Dateisystem vorstellen. Sie + können in einem Dateisystem zwei verschiedene Dateien README.TXT + haben, solange sie sich in verschiedenen Verzeichnissen befinden. + So wie Sie in Verzeichnissen den vollen Pfadnamen eingeben müssen, + um jede Datei von dem obersten Verzeichnis aus zu erreichen, müssen + Sie auch den vollen Namen der aufzurufenden Funktion angeben: Das + heißt für PHP, dass das Hauptverzeichnis der globale Namensbereich, + und der Separator des Pfadnamens -> wäre. Deshalb benennen die + Namen $cart->items und $another_cart->items auch zwei + verschiedene Variablen. Beachten Sie, dass die Variable + $cart->items, und nicht $cart->$items genannt wird, da + ein Variablenname in PHP nur ein einziges Dollarzeichen hat. </para> <informalexample> <programlisting role="php"> <![CDATA[ -// correct, single $ +// korrekt, einfaches $ $cart->items = array("10" => 1); -// invalid, because $cart->$items becomes $cart->"" +// falsch, denn $cart->$items wird zu $cart->"" $cart->$items = array("10" => 1); -// correct, but may or may not be what was intended: -// $cart->$myvar becomes $cart->items +// richtig aber fraglich, ob dies erwünscht war: +// $cart->$myvar wird zu $cart->items $myvar = 'items'; $cart->$myvar = array("10" => 1); ]]> @@ -178,17 +181,17 @@ </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'. + Innerhalb einer Klassendefinition ist nicht bekannt, unter welchem + Namen das Objekt in Ihrem Programm erreichbar sein wird: Als die + Klasse Cart geschrieben wurde war nicht bekannt, dass das Objekt + später $cart oder $another_cart genannt wird. Deshalb können Sie + innerhalb der Klasse Cart selbst auch nicht $cart->items schreiben. + Um nun die eigenen Funktionen und Variablen innerhalb einer Klasse + anzusprechen, können Sie die Pseudo-Variable $this verwenden, welche + Sie auch als 'meine eigene' oder 'aktuelles Objekt' verstehen können. + Deshalb kann '$this->items[$artnr] += $num' auch als 'addiere $num + zu $artnr in meinem eigenen Array items', oder 'addiere $num zu + $artnr im Array items innerhalb des aktuellen Objektes' lesen. </para> </sect1>