tom Sun Apr 7 06:04:16 2002 EDT
Modified files:
/phpdoc/de/language oop.xml
Log:
translated a bit more
Index: phpdoc/de/language/oop.xml
diff -u phpdoc/de/language/oop.xml:1.9 phpdoc/de/language/oop.xml:1.10
--- phpdoc/de/language/oop.xml:1.9 Thu Mar 28 15:44:54 2002
+++ phpdoc/de/language/oop.xml Sun Apr 7 06:04:16 2002
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- EN-Revision: 1.32 Maintainer: tom Status: working -->
+<!-- EN-Revision: 1.33 Maintainer: tom Status: working -->
<chapter id="language.oop">
<title>Klassen und Objekte</title>
@@ -81,7 +81,7 @@
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
+ zur Initialisierung, welche beim Erstellen eines Objektes
automatisch von der Klasse aufgerufen wird. Eine solche Funktion
wird Konstruktor genannt (siehe unten).
</simpara>
@@ -193,25 +193,32 @@
zu $artnr in meinem eigenen Array items', oder 'addiere $num zu
$artnr im Array items innerhalb des aktuellen Objektes' lesen.
</para>
+
+ <note>
+ <para>
+ Es gibt ein paar angenehme Funktionen, um mit Klassen und Objekten umzugehen.
+ Mehr dar�ber erfahren Sie im Kapitel <link linkend="ref.classobj">Klassen-
+ und Objekt-Funktionen</link>.
+ </para>
+ </note>
</sect1>
<sect1 id="keyword.extends">
<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'.
+ Oft braucht man Klassen mit in einer anderen Klasse �hnlichen Variablen
+ und Funktionen. So ist es eine gute Vorgehensweise, eine in allen Ihren
+ Projekten verwendbare Oberklasse zu definieren, und diese dann den
+ Bed�rfnissen Ihrer einzelnen Projekte anzupassen. Um dies zu erleichtern,
+ k�nnen Klassen andere Klassen erweitern. Die erweiterte bzw. abgeleitete
+ Klasse verf�gt �ber alle Variablen und Funktionen der Basisklasse (dies
+ wird 'Vererbung' genannt, obwohl niemand gestorben ist), und was Sie in
+ der erweiterten Definition hinzuf�gen. Es ist nicht m�glich, etwas von
+ einer Klasse wegzunehmen, d.h. Sie k�nnen keine existierenden Variablen
+ oder Funktionen 'wegdefinieren'. Eine Unterklasse ist immer von einer
+ einzigen Oberklasse abh�ngig, d.h. Mehrfachvererbung wird nicht
+ unterst�tzt. Klassen werden mittels dem Schl�sselwort 'extends' erweitert.
</para>
<informalexample>
@@ -231,20 +238,21 @@
</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:
+ Hier wird die Klasse Named_Cart definiert, die �ber alle Variablen
+ und Funktionen von Cart, plus der Variable $owner und der Funktion
+ set_owner() verf�gt. Sie k�nnen einen bestimmten Einkaufswagen
+ (Named_Cart) auf dem �blichen Weg erstellen, und nun auch den
+ Besitzer (owner) bestimmen und erfragen. Sie k�nnen noch immer
+ die normalen Cart Funktionen an Named_Cart anwenden:
</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; // Erstellt einen bestimmten Einkaufwagen
+$ncart->set_owner("kris"); // den Besitzer festlegen
+print $ncart->owner; // den Besitzer ausgeben
+$ncart->add_item("10", 1); // (vererbte Funktionalit�t von Cart)
]]>
</programlisting>
</informalexample>
@@ -252,29 +260,30 @@
</sect1>
<sect1 id="language.oop.constructor">
- <title><literal>Constructors</literal></title>
+ <title><literal>Konstruktoren</literal></title>
<caution>
<simpara>
- In PHP 3 and PHP 4 constructors behave differently. The PHP 4
- semantics are strongly preferred.
+ In PHP 3 und PHP 4 verhalten sich die Konstruktoren
+ unterschiedlich. Die PHP 4 Semantik wird dringend empfohlen.
</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).
+ Konstruktoren sind Funktionen innerhalb einer Klasse, die
+ automatisch aufgerufen wird, sobald Sie mittels
+ <literal>new</literal> eine neue Instanz erstellen. In PHP 3
+ wird eine Funktion zum Konstruktor, wenn sie den gleichen Namen
+ wie die Klasse hat. In PHP 4 wird eine Funktion zum Konstruktor,
+ wenn sie den gleichen Namen wie die Klasse hat, in der sie
+ definiert ist. Der Unterschied ist subtil, aber entscheidend
+ (siehe unten).
</para>
<informalexample>
<programlisting role="php">
<![CDATA[
-// Works in PHP 3 and PHP 4.
+// Funktioniert sowohl in PHP 3, als auch in PHP 4.
class Auto_Cart extends Cart
{
function Auto_Cart()
@@ -287,19 +296,20 @@
</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.
+ Die Klasse Auto_Cart entspricht der Klasse Cart und hat einen
+ Konstruktor, der Cart bereits mit einem Artikel der Nummer "10"
+ initialisiert, sobald ein neuer Auto_Cart mittels "new" erstellt
+ wird. Konstruktoren k�nnen Argumente �bernehmen, die optional
+ sein k�nnen, was sie sehr praktisch macht. Um eine Klasse auch
+ ohne Parameter verwenden zu k�nnen, sollten alle Parameter f�r
+ Konstruktoren optional sein, indem sie mit Standardwerten
+ ausgestattet werden.
</para>
<informalexample>
<programlisting role="php">
<![CDATA[
-// Works in PHP 3 and PHP 4.
+// Funktioniert sowohl in PHP 3, als auch in PHP 4.
class Constructor_Cart extends Cart
{
function Constructor_Cart($item = "10", $num = 1)
@@ -308,11 +318,11 @@
}
}
-// Shop the same old boring stuff.
+// Kaufe das gleiche alte Zeug ein.
$default_cart = new Constructor_Cart;
-// Shop for real...
+// Kaufe etwas anderes...
$different_cart = new Constructor_Cart("20", 17);
]]>
@@ -321,9 +331,9 @@
<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.
+ In PHP 3 haben abgeleitete Klassen und Konstruktoren ein paar
+ Einschr�nkungen. Sie sollten das folgende Beispiel sorgf�ltig
+ lesen, um diese Einschr�nkungen zu verstehen.
</simpara>
</caution>
@@ -346,24 +356,25 @@
}
}
-// no constructor is being called in PHP 3.
+// In PHP 3 wurde kein Konstruktor aufgerufen.
$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.
+ In PHP 3 wird bei dem obigen Beispiel kein Konstruktor aufgerufen.
+ Die Regel in PHP 3 besagt: 'Ein Konstruktor ist eine Funktion mit
+ dem selben Namen wie die Klasse'. Der Name der Klasse ist B, und
+ nachdem in Klasse B keine Funktion namens B() existiert, passiert
+ nichts.
</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.
+ Dies ist in PHP 4 mit der Einf�hrung einer anderen Regel behoben:
+ Wenn eine Klasse keinen Konstruktor hat, wird der Konstruktor der
+ Basisklasse aufgerufen, so dieser existiert. Das obige Beispiel
+ h�tte in PHP 4 also 'I am the constructor of A.<br>' ausgegeben.
</para>
<informalexample>
@@ -391,50 +402,52 @@
}
}
-// This will call B() as a constructor.
+// Dies ruft B() als Konstruktor auf.
$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.
+ In PHP 3 wird die Funktion B() in der Klasse A pl�tzlich zum
+ Konstruktor in Klasse B, auch wenn dies nie beabsichtigt war.
+ Die Regel in PHP 3 lautet: 'Ein Konstruktor ist eine Funktion
+ mit dem gleichen Namen wie die Klasse'. PHP 3 k�mmert sich nicht
+ darum, ob die Funktion in Klasse B definiert, oder ob sie nur
+ vererbt wurde.
</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>'.
+ Dies ist in PHP 4 mit einer modifizierten Regel behoben: 'Ein
+ Konstruktor ist eine Funktion mit dem selben Namen wie die Klasse,
+ in der sie definiert wurde'. So h�tte die Klasse B in dem obigen
+ Beispiel keinen eigenen Konstruktor, und w�rde der Konstruktor
+ der Basisklasse aufgerufen, welcher 'I am the constructor of
+ A.<br>' ausgeben w�rde.
</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.
+ Weder PHP 3, noch PHP 4 rufen vom Konstruktor der abgeleiteten
+ Klasse aus automatisch Konstruktoren der Basisklasse auf. Wenn
+ angebracht, ist der Aufruf von Konstruktoren aufw�rts Ihre
+ Aufgabe.
</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.
+ In PHP 3 und PHP 4 gibt es keine Destruktoren. Stattdessen k�nnen
+ Sie <function>register_shutdown_function</function> verwenden, um
+ die meisten Effekte von Destruktoren zu simulieren.
</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.
+ Destruktoren sind Funktionen die automatisch aufgerufen werden, wenn
+ ein Objekt entweder mittels <function>unset</function>, oder durch
+ Verlassen des G�ltigkeitsbereiches zerst�rt wird. Es gibt in PHP
+ keine Destruktoren.
</para>
</sect1>
@@ -443,15 +456,14 @@
<caution>
<simpara>
- The following is valid for PHP 4 only.
+ Die folgende Beschreibung ist nur f�r PHP 4 g�ltig.
</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.
+ Manchmal ist es hilfreich, auf Funktionen in Basisklassen bzw.
+ auf Funktionen in Klassen zuzugreifen, die noch keine Instanzen
+ haben. Daf�r wird der :: Operator verwendet.
</para>
<informalexample>
@@ -474,15 +486,15 @@
}
}
-// there is no object of class A.
-// this will print
+// Es gibt kein Objekt der Klasse A.
+// Dies wird folgendes ausgeben
// I am the original function A::example().<br>
A::example();
-// create an object of class B.
+// Erstellt ein Objekt der Klasse B.
$b = new B;
-// this will print
+// Dies wird folgendes ausgeben
// I am the redefined function B::example().<br>
// I am the original function A::example().<br>
$b->example();
@@ -491,36 +503,34 @@
</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.
+ Das obige Beispiel ruft die Funktion example() der Klasse A auf.
+ Nachdem noch kein Objekt der Klasse A existiert, k�nnen wir nicht
+ $a->example() oder �hnliches schreiben. Stattdessen rufen wir
+ example() als 'Klassenfunktion' auf, d.h. als Funktion der Klasse
+ selbst, und nicht irgendein Objekt dieser Klasse.
</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.
+ Es gibt Klassenfunktionen, aber keine Klassenvariablen. Tats�chlich
+ gibt es zur Zeit des Aufrufs kein Objekt. Deshalb darf eine
+ Klassenfunktion keine Objektvariablen benutzen (aber sie kann lokale
+ und globale Variablen verwenden), und sie darf $this ebenfalls nicht
+ benutzen.
</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).
+ In dem obigen Beispiel definiert Klasse B die Funktion example() neu.
+ Die urspr�ngliche Definition in Klasse A ist �berschattet und nicht
+ l�nger verf�gbar, au�er Sie verweisen mittels des ::-Operators
+ speziell auf example() in Klasse A. Schreiben Sie A::example(), um
+ dies zu tun (Tats�chlich sollten Sie parent::example() schreiben,
+ wie im n�chsten Abschnitt beschrieben).
</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.
+ In diesem Kontext besteht ein Objekt, das Objektvariablen haben
+ kann. Deshalb k�nnen Sie auch $this und Objektvariablen verwenden,
+ wenn sie von innerhalb einer Objektfunktion verwendet werden.
</para>
</sect1>
@@ -529,22 +539,22 @@
<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.
+ Wahrscheinlich wollen Sie auch Code schreiben, der sich auch auf
+ Variablen und Funktionen in Basisklassen bezieht. Dies gilt
+ speziell dann, wenn Ihre abgeleitete Klasse eine Verfeinerung
+ oder Spezialisierung von Code in Ihrer Basisklasse ist.
</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.
+ Anstatt in Ihrem Code den w�rtlichen Namen der Basisklasse zu
+ verwenden, sollten Sie den speziellen Namen
+ <literal>parent</literal> verwenden, welcher sich auf den in
+ der Deklaration Ihrer Klasse mittels <literal>extends</literal>
+ gegebenen Namen Ihrer Basisklasse bezieht. So vermeiden Sie
+ die mehrfache Verwendung des Namens der Basisklasse. Sollte
+ sich Ihr Vererbungsbaum w�hrend der Implementation �ndern,
+ brauchen Sie nur mehr die <literal>extends</literal> Deklaration
+ Ihrer Klasse zu �ndern.
</para>
<informalexample>
@@ -569,7 +579,7 @@
$b = new B;
-// This will call B::example(), which will in turn call A::example().
+// Dies ruft B::example() auf, welches wiederum A::example() aufruft.
$b->example();
]]>
</programlisting>
@@ -577,45 +587,47 @@
</sect1>
<sect1 id="language.oop.serialization">
- <title>Serializing objects - objects in sessions</title>
+ <title>Objekte serialisieren - Objekte in Sessions</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).
+ In PHP 3 verlieren Objekte w�hrend des Prozesses der Serialisierung
+ und Deserialisierung ihre Assoziation zur Klasse. Die resultierende
+ Variable ist vom Typ Objekt, hat aber keine Klasse und keine Methoden,
+ weshalb sie ziemlich unbrauchbar ist (Sie wurde wie ein Array, jedoch
+ mit einer ziemlich komischen Syntax).
</simpara>
</note>
<caution>
<simpara>
- The following information is valid for PHP 4 only.
+ Die folgende Information ist nur f�r PHP 4 g�ltig.
</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> gibt eine Zeichenkette zur�ck, die
+ eine Byte-Strom-Repr�sentation irgendeines in PHP speicherbaren
+ Wertes enth�lt. <function>unserialize</function> kann diese
+ Zeichenkette verwenden, um die urspr�nglichen Variablenwerte
+ wieder herzustellen. Die Verwendung von serialize zum Speichern
+ eines Objektes wird alle Variablen innerhalb eines Objektes
+ speichern. Die Funktionen in einem Objekt werden nicht gespeichert,
+ sondern nur der Name der Klasse.
</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.
+ Um ein Objekt wieder deserialisieren zu k�nnen, muss die Klasse
+ dieses Objektes definiert werden. Das hei�t, wenn Sie ein Objekt
+ $a der Klasse A in page1.php haben und dieses serialisieren,
+ erhalten Sie eine Zeichenkette, die sich auf die Klasse A bezieht,
+ und alle Werte der in $a enthaltenen Variablen enth�lt. Wenn Sie
+ $a der Klasse A in page2.php mittels unserialize wiederherstellen
+ m�chten, muss die Definition von Klasse A in page2.php vorhanden
+ sein. Dies kann zum Beispiel durch das Speichern der
+ Klassendefiniton von Klasse A in einer Include-Datei, und das
+ Einbinden dieser Datei sowohl in page1.php und page2.php realisiert
+ werden.
</para>
<informalexample>
@@ -637,49 +649,48 @@
$a = new A;
$s = serialize($a);
- // store $s somewhere where page2.php can find it.
+ // speichere $s irgendwo, wo sie page2.php finden kann.
$fp = fopen("store", "w");
fputs($fp, $s);
fclose($fp);
page2.php:
- // this is needed for the unserialize to work properly.
+ // Dies ist f�r das korrekte Arbeiten von unserialize n�tig.
include("classa.inc");
$s = implode("", @file("store"));
$a = unserialize($s);
- // now use the function show_one() of the $a object.
+ // Nun verwenden wir die Funktion show_one() des Objektes $a.
$a->show_one();
]]>
</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.
+ Wenn Sie mit Sessions arbeiten und <function>session_register</function>
+ verwenden, um Objekte zu registrieren, so werden diese Objekte am Ende
+ der PHP Seite serialisiert, und in jeder folgenden Seite automatisch
+ via unserialize wiederhergestellt. Das hei�t, dass diese Objekte auf
+ jeder Ihrer Seite auftauchen k�nnen, sobald sie Teil Ihrer Session sind.
</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.
+ Es wird ausdr�cklich empfohlen, dass Sie die Klassendefinitionen der
+ so registrierten Objekte in allen Ihren Seiten einbinden, auch wenn
+ Sie diese Klassen eigentlich nicht auf allen Ihren Seiten ben�tigen.
+ Tun Sie es nicht und wird ein Objekt ohne einer vorhandenen
+ Klassendefinition deserialisiert, verliert es seine Assoziation zur
+ Klasse, und wird zu einem Objekt der Klasse <literal>stdClass</literal>,
+ ohne irgendwelchen Funktionen. Das bedeutet, dass es ziemlich nutzlos
+ wird.
</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.
+ W�rde also $a in dem obigen Beispiel mittels
+ <literal>session_register("a")</literal> ein Teil einer Session,
+ sollten Sie die Datei <literal>classa.inc</literal> nicht nur in
+ page1.php und page2.php, sondern in all Ihre Seiten einbinden.
</para>
</sect1>