1
0
mirror of https://github.com/php/doc-de.git synced 2026-03-23 23:02:13 +01:00

Sync with EN

This commit is contained in:
Martin Samesch
2025-04-23 13:42:49 +02:00
parent 55cafb9a2c
commit e978f2d900
12 changed files with 255 additions and 185 deletions

View File

@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: f908fff129bcd8ec1605658e06457cb04e5b2b51 Maintainer: hholzgra Status: ready -->
<!-- EN-Revision: e587d0655e426f97b3fcb431453da5030e743b23 Maintainer: hholzgra Status: ready -->
<!-- Reviewed: yes -->
<!-- Rev-Revision: 9fe810352095922a68ce2807745a9bc35c0afe1f Reviewer: samesch -->
<!-- CREDITS: samesch, betz -->
<chapter xml:id="language.types" xmlns="http://docbook.org/ns/docbook">
<chapter xml:id="language.types" xmlns="http://docbook.org/ns/docbook" annotations="interactive">
<title>Typen</title>
<sect1 xml:id="language.types.intro">
@@ -77,7 +77,8 @@
<literal>is_<replaceable>type</replaceable></literal>-Funktionen verwendet
werden.
<informalexample>
<example>
<title>Verschiedene Typen</title>
<programlisting role="php">
<![CDATA[
<?php
@@ -110,7 +111,7 @@ string
int(16)
]]>
</screen>
</informalexample>
</example>
</para>
<note>
<simpara>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 22583751fbfdaa3eaa41aeb6470d1343f5cb2c78 Maintainer: cmb Status: ready -->
<!-- EN-Revision: e587d0655e426f97b3fcb431453da5030e743b23 Maintainer: cmb Status: ready -->
<!-- Reviewed: yes -->
<!-- Rev-Revision: c140370c354496b38b97dfafe2e31f3f8df8bb44 Reviewer: samesch -->
<sect1 xml:id="language.types.array">
@@ -68,16 +68,18 @@ array(
<programlisting role="php">
<![CDATA[
<?php
$array = array(
$array1 = array(
"foo" => "bar",
"bar" => "foo",
);
// Verwendung der verkürzten Array-Syntax
$array = [
$array2 = [
"foo" => "bar",
"bar" => "foo",
];
var_dump($array1, $array2);
?>
]]>
</programlisting>
@@ -457,6 +459,8 @@ function getArray() {
}
$secondElement = getArray()[1];
var_dump($secondElement);
?>
]]>
</programlisting>
@@ -535,7 +539,8 @@ $arr[] = <replaceable>Wert</replaceable>;
kann man die Funktion <function>unset</function> darauf anwenden.
</para>
<informalexample>
<example>
<title>Verwenden von eckigen Klammern bei Arrays</title>
<programlisting role="php">
<![CDATA[
<?php
@@ -549,12 +554,15 @@ $arr["x"] = 42; // Dies fügt ein neues Element zum Array
unset($arr[5]); // Dies entfernt das Element aus dem Array
var_dump($arr);
unset($arr); // Dies löscht das gesamte Array
var_dump($arr);
?>
]]>
</programlisting>
</informalexample>
</example>
<note>
<para>
@@ -640,7 +648,8 @@ Array
zerlegen.
</para>
<informalexample>
<example>
<title>Destrukturieren eines Arrays</title>
<programlisting role="php">
<![CDATA[
<?php
@@ -648,20 +657,21 @@ $source_array = ['foo', 'bar', 'baz'];
[$foo, $bar, $baz] = $source_array;
echo $foo; // gibt "foo" aus
echo $bar; // gibt "bar" aus
echo $baz; // gibt "baz" aus
echo $foo, PHP_EOL; // gibt "foo" aus
echo $bar, PHP_EOL; // gibt "bar" aus
echo $baz, PHP_EOL; // gibt "baz" aus
?>
]]>
</programlisting>
</informalexample>
</example>
<para>
Die Destrukturierung von Arrays kann in &foreach; verwendet werden, um
ein mehrdimensionales Array zu zerlegen, während darüber iteriert wird.
</para>
<informalexample>
<example>
<title>Destrukturieren eines Arrays in foreach</title>
<programlisting role="php">
<![CDATA[
<?php
@@ -671,12 +681,12 @@ $source_array = [
];
foreach ($source_array as [$id, $name]) {
// der Code mit $id und $name
echo "{$id}: '{$name}'\n";
}
?>
]]>
</programlisting>
</informalexample>
</example>
<para>
Array-Elemente werden ignoriert, wenn die Variable nicht angegeben wird.
@@ -684,7 +694,8 @@ foreach ($source_array as [$id, $name]) {
<literal>0</literal>.
</para>
<informalexample>
<example>
<title>Ignoren von Elementen</title>
<programlisting role="php">
<![CDATA[
<?php
@@ -697,7 +708,7 @@ echo $baz; // gibt "baz" aus
?>
]]>
</programlisting>
</informalexample>
</example>
<para>
Seit PHP 7.1.0 können auch assoziative Arrays destrukturiert werden. Da
@@ -706,7 +717,8 @@ echo $baz; // gibt "baz" aus
Elements.
</para>
<informalexample>
<example>
<title>Destrukturieren von assoziativen Arrays</title>
<programlisting role="php">
<![CDATA[
<?php
@@ -715,14 +727,14 @@ $source_array = ['foo' => 1, 'bar' => 2, 'baz' => 3];
// Zuweisen des Elements bei Index 'baz' an die Variable $three
['baz' => $three] = $source_array;
echo $three; // gibt 3 aus
echo $three, PHP_EOL; // gibt 3 aus
$source_array = ['foo', 'bar', 'baz'];
// Zuweisen des Elements bei Index 2 an die Variable $baz
[2 => $baz] = $source_array;
echo $baz; // gibt "baz" aus
echo $baz, PHP_EOL; // gibt "baz" aus
?>
]]>
</programlisting>
@@ -733,7 +745,8 @@ echo $baz; // gibt "baz" aus
Variablen zu vertauschen.
</para>
<informalexample>
<example>
<title>Vertauschen von zwei Variablen</title>
<programlisting role="php">
<![CDATA[
<?php
@@ -742,12 +755,12 @@ $b = 2;
[$b, $a] = [$a, $b];
echo $a; // gibt 2 aus
echo $b; // gibt 1 aus
echo $a, PHP_EOL; // gibt 2 aus
echo $b, PHP_EOL; // gibt 1 aus
?>
]]>
</programlisting>
</informalexample>
</example>
<note>
<para>
@@ -788,24 +801,28 @@ echo $b; // gibt 1 aus
werden.
</para>
<informalexample>
<example>
<title>Entfernen von Zwischenelementen</title>
<programlisting role="php">
<![CDATA[
<?php
$a = array(1 => 'one', 2 => 'two', 3 => 'three');
unset($a[2]);
/* dies wird ein Array erzeugen, das wie folgt definiert worden wäre
$a = array(1 => 'one', 3 => 'three');
und NICHT so
$a = array(1 => 'one', 2 =>'three');
*/
unset($a[2]);
var_dump($a);
$b = array_values($a);
// Nun ist $b array(0 => 'one', 1 =>'three')
var_dump($b);
?>
]]>
</programlisting>
</informalexample>
</example>
</note>
<para>
@@ -864,26 +881,28 @@ echo $foo[bar];
</simpara>
</warning>
<note>
<simpara>
Dies bedeutet nicht, dass man den Schlüssel <emphasis>immer</emphasis> in
Anführungszeichen setzen muss. Setzen Sie keine Schlüssel in
Anführungszeichen, welche
<link linkend="language.constants">Konstanten</link> oder
<link linkend="language.variables">Variablen</link> sind, da dies PHP
daran hindern wird, diese zu interpretieren.
</simpara>
<simpara>
Dies bedeutet nicht, dass man den Schlüssel <emphasis>immer</emphasis> in
Anführungszeichen setzen muss. Setzen Sie keine Schlüssel in
Anführungszeichen, welche
<link linkend="language.constants">Konstanten</link> oder
<link linkend="language.variables">Variablen</link> sind, da dies PHP
daran hindern wird, diese zu interpretieren.
</simpara>
<informalexample>
<programlisting role="php">
<example>
<title>Anführungszeichen bei Schlüsseln</title>
<programlisting role="php">
<![CDATA[
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('html_errors', false);
// Ein simples Array:
$array = array(1, 2);
$count = count($array);
for ($i = 0; $i < $count; $i++) {
echo "\nPrüfe $i: \n";
echo "Schlecht: " . $array['$i'] . "\n";
@@ -893,10 +912,10 @@ for ($i = 0; $i < $count; $i++) {
}
?>
]]>
</programlisting>
</informalexample>
&example.outputs;
<screen>
</programlisting>
</example>
&example.outputs;
<screen>
<![CDATA[
Prüfe 0:
Notice: Undefined index: $i in /path/to/script.html on line 9
@@ -914,14 +933,14 @@ Notice: Undefined index: $i in /path/to/script.html on line 11
Schlecht:
Gut: 2
]]>
</screen>
</note>
</screen>
<para>
Weitere Beispiele zur Erläuterung dieses Verhaltens:
</para>
<informalexample>
<example>
<title>Weitere Beispiele</title>
<programlisting role="php">
<![CDATA[
<?php
@@ -931,46 +950,53 @@ error_reporting(E_ALL);
$arr = array('fruit' => 'apple', 'veggie' => 'carrot');
// Korrekt
print $arr['fruit']; // apple
print $arr['veggie']; // carrot
echo $arr['fruit'], PHP_EOL; // apple
echo $arr['veggie'], PHP_EOL; // carrot
// Inkorrekt. Dies Funktioniert, aber PHP wirft einen Fehler der Stufe
// E_NOTICE, da eine undefinierte Konstante namens fruit verwendet wird
// Inkorrekt. Dies Funktioniert, aber PHP löst einen Error aus,
// da eine undefinierte Konstante namens fruit verwendet wird
//
// Notice: Use of undefined constant fruit - assumed 'fruit' in...
print $arr[fruit]; // apple
// Error: Undefined constant "fruit"
try {
echo $arr[fruit]; // apple
} catch (Error $e) {
echo get_class($e), ': ', $e->getMessage(), PHP_EOL;
}
// Dies definiert eine Konstante, um darzustellen, was hier passiert. Der Wert
// 'veggie' wird einer Konstanten namens fruit zugewiesen
define('fruit', 'veggie');
// Beachten Sie nun den Unterschied
print $arr['fruit']; // apple
print $arr[fruit]; // carrot
echo $arr['fruit'], PHP_EOL; // apple
echo $arr[fruit], PHP_EOL; // carrot
// Hier ist es in Ordnung, da dies innerhalb eines Strings ist. Innerhalb eines
// Strings wird nicht nach Konstanten gesucht, weshalb kein E_NOTICE auftritt
print "Hello $arr[fruit]"; // Hello apple
echo "Hello $arr[fruit]", PHP_EOL; // Hello apple
// Mit einer Ausnahme: Klammern um ein Array sorgen dafür, dass Konstanten
// interpretiert werden
print "Hello {$arr[fruit]}"; // Hello carrot
print "Hello {$arr['fruit']}"; // Hello apple
echo "Hello {$arr[fruit]}", PHP_EOL; // Hello carrot
echo "Hello {$arr['fruit']}", PHP_EOL; // Hello apple
// Konkatenation (Verkettung) ist eine weitere Möglichkeit
print "Hello " . $arr['fruit']; // Hello apple
echo "Hello " . $arr['fruit'], PHP_EOL; // Hello apple
?>
]]>
</programlisting>
</informalexample>
</example>
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
// Dies wird nicht funktionieren und zu einem Parse-Fehler führen:
// Parse error: parse error, expecting T_STRING' or T_VARIABLE' or T_NUM_STRING'
// Dies gilt natürlich ebenso für superglobale Werte innerhalb von Strings
print "Hello $arr['fruit']";
print "Hello $_GET['foo']";
?>
]]>
</programlisting>
</informalexample>
@@ -1093,7 +1119,8 @@ $error_descriptions[8] = "Dies ist nur ein informeller Hinweis";
werden stillschweigend verworfen.
</para>
<informalexample>
<example>
<title>Konvertierung in ein Array</title>
<programlisting role="php">
<![CDATA[
<?php
@@ -1123,14 +1150,15 @@ array (
)
]]>
</screen>
</informalexample>
</example>
<para>
Diese <literal>NUL</literal>-Bytes können zu einem unerwarteten Verhalten
führen:
</para>
<informalexample>
<example>
<title>Umwandeln eines Objekts in ein Array</title>
<programlisting role="php">
<![CDATA[
<?php
@@ -1161,7 +1189,7 @@ array(3) {
}
]]>
</screen>
</informalexample>
</example>
<para>
Im obigen Beispiel scheint es zwei Schlüssel namens 'AA' zu geben, obwohl
@@ -1207,15 +1235,17 @@ array(3) {
// Verwendung der kurzen Array-Syntax.
// Funktioniert auch mit der array()-Syntax.
$arr1 = [1, 2, 3];
$arr2 = [...$arr1]; //[1, 2, 3]
$arr3 = [0, ...$arr1]; //[0, 1, 2, 3]
$arr4 = [...$arr1, ...$arr2, 111]; //[1, 2, 3, 1, 2, 3, 111]
$arr5 = [...$arr1, ...$arr1]; //[1, 2, 3, 1, 2, 3]
$arr2 = [...$arr1]; // [1, 2, 3]
$arr3 = [0, ...$arr1]; // [0, 1, 2, 3]
$arr4 = [...$arr1, ...$arr2, 111]; // [1, 2, 3, 1, 2, 3, 111]
$arr5 = [...$arr1, ...$arr1]; // [1, 2, 3, 1, 2, 3]
function getArr() {
return ['a', 'b'];
}
$arr6 = [...getArr(), 'c' => 'd']; //['a', 'b', 'c' => 'd']
$arr6 = [...getArr(), 'c' => 'd']; // ['a', 'b', 'c' => 'd']
var_dump($arr1, $arr2, $arr3, $arr4, $arr5, $arr6);
?>
]]>
</programlisting>
@@ -1292,7 +1322,8 @@ $arr6 = [...$arr4, ...$arr5]; // works. [1, 2, 3, 4, 5]
Der Array-Typ in PHP ist sehr vielseitig. Hier sind einige Beispiele:
</para>
<informalexample>
<example>
<title>Vielseitigkeit von Arrays</title>
<programlisting role="php">
<![CDATA[
<?php
@@ -1306,6 +1337,8 @@ $a = array( 'color' => 'red',
$b = array('a', 'b', 'c');
var_dump($a, $b);
// . . .ist komplett gleichbedeutend mit:
$a = array();
$a['color'] = 'red';
@@ -1324,10 +1357,12 @@ $b[] = 'c';
// 'name' => 'apple', 0 => 4) sein und $b wird das Array
// array(0 => 'a', 1 => 'b', 2 => 'c') oder einfach array('a', 'b', 'c')
// sein
var_dump($a, $b);
?>
]]>
</programlisting>
</informalexample>
</example>
<example>
<title>Verwendung von array()</title>
@@ -1340,15 +1375,17 @@ $map = array( 'version' => 4,
'lang' => 'englisch',
'short_tags' => true
);
var_dump($map);
// Streng numerische Schlüssel
// Das ist gleichbedeutend mit array(0 => 7, 1 => 8, ...)
$array = array( 7,
8,
0,
156,
-10
);
// das ist gleichbedeutend mit array(0 => 7, 1 => 8, ...)
var_dump($array);
$switching = array( 10, // Schlüssel = 0
5 => 6,
@@ -1359,9 +1396,11 @@ $switching = array( 10, // Schlüssel = 0
'02' => 77, // Schlüssel = '02'
0 => 12 // Der Wert 10 wird mit 12 überschrieben
);
var_dump($switching);
// Leeres array
$empty = array();
var_dump($empty);
?>
]]>
<!-- TODO example of
@@ -1407,6 +1446,8 @@ Mögen sie gelb?
<programlisting role="php">
<![CDATA[
<?php
$colors = array('red', 'blue', 'green', 'yellow');
foreach ($colors as &$color) {
$color = mb_strtoupper($color);
}
@@ -1440,7 +1481,7 @@ Array
<programlisting role="php">
<![CDATA[
<?php
$firstquarter = array(1 => 'Januar', 'Februar', 'März');
$firstquarter = array(1 => 'Januar', 'Februar', 'März');
print_r($firstquarter);
?>
]]>
@@ -1450,9 +1491,9 @@ print_r($firstquarter);
<![CDATA[
Array
(
[1] => 'Januar'
[2] => 'Februar'
[3] => 'März'
[1] => Januar
[2] => Februar
[3] => März
)
]]>
</screen>
@@ -1469,6 +1510,8 @@ while (false !== ($file = readdir($handle))) {
$files[] = $file;
}
closedir($handle);
var_dump($files);
?>
]]>
</programlisting>
@@ -1484,7 +1527,7 @@ closedir($handle);
<example>
<title>Ein Array sortieren</title>
<programlisting role="php">
<programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php
sort($files);
@@ -1521,6 +1564,7 @@ $fruits = array ( "fruits" => array ( "a" => "orange",
"third"
)
);
var_dump($fruits);
// Einige Beispiele für den Zugriff auf die Werte in den obigen Beispielen
echo $fruits["holes"][5]; // gibt "second" aus
@@ -1529,6 +1573,7 @@ unset($fruits["holes"][0]); // entfernt "first"
// Ein neues mehrdimensionales Array erzeugen
$juices["apple"]["green"] = "good";
var_dump($juices);
?>
]]>
</programlisting>
@@ -1541,7 +1586,8 @@ $juices["apple"]["green"] = "good";
per Referenz zu kopieren.
</para>
<informalexample>
<example>
<title>Kopieren eines Arrays</title>
<programlisting role="php">
<![CDATA[
<?php
@@ -1552,10 +1598,12 @@ $arr2[] = 4; // $arr2 wurde geändert,
$arr3 = &$arr1;
$arr3[] = 4; // nun sind $arr1 und $arr3 identisch
var_dump($arr1, $arr2, $arr3);
?>
]]>
</programlisting>
</informalexample>
</example>
</sect2>
</sect1>

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 161dde4fe721309398dd324edbf02aec409f127b Maintainer: hholzgra Status: ready -->
<!-- EN-Revision: e587d0655e426f97b3fcb431453da5030e743b23 Maintainer: hholzgra Status: ready -->
<!-- Reviewed: yes -->
<!-- Rev-Revision: 346c0bd13f99888108cbefeb9c7c17923cac1a47 Reviewer: samesch -->
<sect1 xml:id="language.types.boolean">
@@ -62,7 +61,7 @@ if ($show_separators) {
</sect2>
<sect2 xml:id="language.types.boolean.casting">
<title>Converting to boolean</title>
<title>Umwandlung in Boolean</title>
<simpara>
Um einen Wert explizit in <type>bool</type> zu konvertieren, kann der
@@ -136,7 +135,8 @@ if ($show_separators) {
</simpara>
</warning>
<informalexample>
<example>
<title>Umwandlung in Boolean</title>
<programlisting role="php">
<![CDATA[
<?php
@@ -152,7 +152,7 @@ var_dump((bool) "false"); // bool(true)
?>
]]>
</programlisting>
</informalexample>
</example>
</sect2>
</sect1>

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: c897161ca5a62a887295c695adc161b8fde5d772 Maintainer: simp Status: ready -->
<!-- EN-Revision: e587d0655e426f97b3fcb431453da5030e743b23 Maintainer: simp Status: ready -->
<!-- Reviewed: no -->
<sect1 xml:id="language.types.callable">
<title>Callbacks / Callables</title>
@@ -80,13 +79,13 @@
// Eine Beispiel-Callback-Funktion
function my_callback_function() {
echo 'hello world!';
echo 'hello world!', PHP_EOL;
}
// Eine Beispiel-Callback-Methode
class MyClass {
static function myCallbackMethod() {
echo 'Hello World!';
echo 'Hello World!', PHP_EOL;
}
}
@@ -106,13 +105,13 @@ call_user_func('MyClass::myCallbackMethod');
// Typ 5: Relativer statischer Methodenaufruf
class A {
public static function who() {
echo "A\n";
echo 'A', PHP_EOL;
}
}
class B extends A {
public static function who() {
echo "B\n";
echo 'B', PHP_EOL;
}
}
@@ -121,7 +120,7 @@ call_user_func(array('B', 'parent::who')); // A, seit PHP 8.2.0 veraltet
// Typ 6: Objekte die __invoke implementieren können als Callable verwendet werden
class C {
public function __invoke($name) {
echo 'Hello ', $name, "\n";
echo 'Hello ', $name, PHP_EOL;
}
}

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 68976f0e68dbd2c49eaf5d477b6075864a946593 Maintainer: samesch Status: ready -->
<!-- EN-Revision: e587d0655e426f97b3fcb431453da5030e743b23 Maintainer: samesch Status: ready -->
<!-- Reviewed: no -->
<sect1 xml:id="language.types.declarations">
<title>Typdeklarationen</title>
@@ -323,8 +323,8 @@ Stack trace:
<literal>null</literal> zum Standardwert gemacht wird. Dies ist jedoch
nicht empfehlenswert, denn wenn der Standardwert in einer Kindklasse
geändert wird, wird eine Verletzung der Typkompatibilität ausgelöst, da
der Typ <literal>null</literal> zur Typdeklaration hinzugefügt werden
muss.
der Typ <type>null</type> zur Typdeklaration hinzugefügt werden muss.
Darüber hinaus ist dieses Verhalten seit PHP 8.4 veraltet.
</para>
<example>
<title>Die alte Methode, um Parameter nullable zu machen</title>
@@ -623,7 +623,7 @@ NULL
<example>
<title>Deklaration eines nulllable Rückgabetyps</title>
<programlisting role="php">
<programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php
function get_item(): ?string {
@@ -640,7 +640,7 @@ function get_item(): ?string {
<example>
<title>Deklaration eines Klasseneigenschafts-Typs</title>
<programlisting role="php">
<programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php
class User {
@@ -713,7 +713,7 @@ class User {
<example>
<title>Strikte Typisierung für die Werte von Argumenten</title>
<programlisting role="php">
<programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php
declare(strict_types=1);
@@ -768,7 +768,7 @@ int(3)
<example>
<title>Strikte Typisierung für Rückgabewerte</title>
<programlisting role="php">
<programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php
declare(strict_types=1);

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: a1e3d629b4f01ee41bd38391cd5c6ae5ee894cb3 Maintainer: simp Status: ready -->
<!-- EN-Revision: e587d0655e426f97b3fcb431453da5030e743b23 Maintainer: simp Status: ready -->
<!-- Reviewed: yes -->
<!-- Rev-Revision: d494ffa4d9f83b60fe66972ec2c0cf0301513b4a Reviewer: samesch -->
<sect1 xml:id="language.types.float" xmlns:xlink="http://www.w3.org/1999/xlink">
@@ -139,11 +138,13 @@ EXPONENT_DNUM (({LNUM} | {DNUM}) [eE][+-]? {LNUM})
in der Berechnung dar.
</para>
<informalexample>
<simpara>
<varname>$a</varname> und <varname>$b</varname> sind bis auf 5
Nachkommastellen gleich.
</simpara>
<para>
<varname>$a</varname> und <varname>$b</varname> sind bis auf 5
Nachkommastellen gleich.
</para>
<example>
<title>Vergleichen von Gleitkommazahlen</title>
<programlisting role="php">
<![CDATA[
<?php
@@ -151,13 +152,13 @@ $a = 1.23456789;
$b = 1.23456780;
$epsilon = 0.00001;
if(abs($a-$b) < $epsilon) {
if (abs($a - $b) < $epsilon) {
echo "true";
}
?>
]]>
</programlisting>
</informalexample>
</example>
</sect2>
<sect2 xml:id="language.types.float.nan">

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 8859c8b96cd9e80652813f7bcf561432a5e9f934 Maintainer: samesch Status: ready -->
<!-- EN-Revision: e587d0655e426f97b3fcb431453da5030e743b23 Maintainer: samesch Status: ready -->
<!-- Reviewed: no -->
<sect1 xml:id="language.types.integer">
<title>Ganzzahlen (Integer)</title>
@@ -48,7 +47,7 @@
<example>
<title>Integer-Literale</title>
<programlisting role="php">
<programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php
$a = 1234; // Dezimalzahl
@@ -140,7 +139,8 @@ var_dump(PHP_INT_MAX + 1); // 32-bit-System: float(2147483648)
über das Runden ermöglicht.
</para>
<informalexample>
<example>
<title>Divisionen</title>
<programlisting role="php">
<![CDATA[
<?php
@@ -150,7 +150,7 @@ var_dump(round(25/7)); // float(4)
?>
]]>
</programlisting>
</informalexample>
</example>
</sect2>
<sect2 xml:id="language.types.integer.casting">
@@ -197,7 +197,9 @@ var_dump(round(25/7)); // float(4)
Genauigkeit abnimmt.
</simpara>
<programlisting role="php">
<example>
<title>Umwandlung von Float</title>
<programlisting role="php">
<![CDATA[
<?php
@@ -213,7 +215,8 @@ var_dump((int) 8.1); // in beiden Fällen 8
var_dump(intval(8.1)); // in beiden Fällen 8
?>
]]>
</programlisting>
</programlisting>
</example>
<para>
Wenn der Float-Wert außerhalb der Grenzen von <type>int</type> liegt (auf

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 161dde4fe721309398dd324edbf02aec409f127b Maintainer: samesch Status: ready -->
<!-- EN-Revision: e587d0655e426f97b3fcb431453da5030e743b23 Maintainer: samesch Status: ready -->
<!-- Reviewed: no -->
<sect1 xml:id="language.types.iterable">
<title>Iterable</title>
@@ -33,6 +32,9 @@ function gen(): iterable {
yield 3;
}
foreach(gen() as $value) {
echo $value, "\n";
}
?>
]]>
</programlisting>

View File

@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 7ba2406e555a240338d63f72d9ac54a46e0bee5d Maintainer: samesch Status: ready -->
<!-- EN-Revision: e587d0655e426f97b3fcb431453da5030e743b23 Maintainer: samesch Status: ready -->
<!-- Reviewed: no -->
<!-- $Revision$ -->
<sect1 xml:id="language.types.numeric-strings" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Numerische Zeichenketten</title>
<para>
@@ -40,6 +39,9 @@ NUM_STRING ({INT_NUM_STRING} | {FLOAT_NUM_STRING})
Kleinschreibung wird nicht berücksichtigt) enthält, wird als Zahl in
wissenschaftlicher Notation betrachtet. Dies kann zu unerwarteten
Ergebnissen führen.
</para>
<example>
<title>Vergleich wissenschaftlicher Schreibweisen</title>
<programlisting role="php">
<![CDATA[
<?php
@@ -49,7 +51,7 @@ var_dump("2E1" == "020"); // true, "2E1" ist 2 * (10 ^ 1) also 20
?>
]]>
</programlisting>
</para>
</example>
</note>
<sect2 xml:id="language.types.numeric-string.conversion">

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 4c4b82965384d55f5c3efb1ffa80615acd98a737 Maintainer: nobody Status: ready -->
<!-- EN-Revision: e587d0655e426f97b3fcb431453da5030e743b23 Maintainer: nobody Status: ready -->
<!-- Reviewed: yes -->
<!-- Rev-Revision: 4c4b82965384d55f5c3efb1ffa80615acd98a737 Reviewer: samesch -->
<!-- Credits: hholzgra, simp -->
@@ -15,7 +14,8 @@
der Anweisung <literal>new</literal> eine Klasse instanziiert wird:
</para>
<informalexample>
<example>
<title>Erstellen eines Objekts</title>
<programlisting role="php">
<![CDATA[
<?php
@@ -32,7 +32,7 @@ $bar->do_foo();
?>
]]>
</programlisting>
</informalexample>
</example>
<simpara>
Eine ausführliche Erörterung ist im Kapitel
@@ -56,24 +56,28 @@ $bar->do_foo();
zugegriffen werden konnte, es sei denn, sie wurden iteriert.
</para>
<informalexample>
<example>
<title>Konvertierung in ein Objekt</title>
<programlisting role="php">
<![CDATA[
<?php
$obj = (object) array('1' => 'foo');
var_dump(isset($obj->{'1'})); // Ausgabe 'bool(true)' von PHP 7.2.0 an; 'bool(false)' zuvor
var_dump(key($obj)); // Ausgabe 'string(1) "1"' von PHP 7.2.0 an; 'int(1)' zuvor
var_dump(isset($obj->{'1'})); // outputs 'bool(true)'
// Seit PHP 8.1 veraltet
var_dump(key($obj)); // outputs 'string(1) "1"'
?>
]]>
</programlisting>
</informalexample>
</example>
<para>
Für alle anderen Werte enthält eine Member-Variable namens
<literal>scalar</literal> den Wert.
</para>
<informalexample>
<example>
<title>Konvertierung mittels <literal>(object)</literal></title>
<programlisting role="php">
<![CDATA[
<?php
@@ -82,7 +86,7 @@ echo $obj->scalar; // Ausgabe 'ciao'
?>
]]>
</programlisting>
</informalexample>
</example>
</sect2>
</sect1>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: ef5a00895dbb9a3abbe3edc03d1f966b239a2eb2 Maintainer: nobody Status: ready -->
<!-- EN-Revision: e587d0655e426f97b3fcb431453da5030e743b23 Maintainer: nobody Status: ready -->
<!-- Reviewed: no -->
<sect1 xml:id="language.types.string">
<title>Strings (Zeichenketten)</title>
@@ -82,34 +82,35 @@
</simpara>
</note>
<informalexample>
<example>
<title>Syntax-Varianten</title>
<programlisting role="php">
<![CDATA[
<?php
echo 'dies ist ein einfacher String';
echo 'dies ist ein einfacher String', PHP_EOL;
echo 'Sie können auch Zeilenumbrüche
in dieser Art angeben,
dies ist okay so';
dies ist okay so', PHP_EOL;
// Gibt aus: Arnold sagte einst: "I'll be back"
echo 'Arnold sagte einst: "I\'ll be back"';
echo 'Arnold sagte einst: "I\'ll be back"', PHP_EOL;
// Ausgabe: Sie löschten C:\*.*?
echo 'Sie löschten C:\\*.*?';
echo 'Sie löschten C:\\*.*?', PHP_EOL;
// Ausgabe: Sie löschten C:\*.*?
echo 'Sie löschten C:\*.*?';
echo 'Sie löschten C:\*.*?', PHP_EOL;
// Ausgabe: Dies erzeugt keinen: \n Zeilenumbruch
echo 'Dies erzeugt keinen: \n Zeilenumbruch';
echo 'Dies erzeugt keinen: \n Zeilenumbruch', PHP_EOL;
// Ausgabe: Variablen werden $ebenfalls $nicht ersetzt
echo 'Variablen werden $ebenfalls $nicht ersetzt';
echo 'Variablen werden $ebenfalls $nicht ersetzt', PHP_EOL;
?>
]]>
</programlisting>
</informalexample>
</example>
</sect3>
@@ -295,7 +296,7 @@ c
&example.outputs.73;
<screen>
<![CDATA[
PHP Parse error: Invalid body indentation level (expecting an indentation level of at least 3) in example.php on line 4
Parse error: Invalid body indentation level (expecting an indentation level of at least 3) in example.php on line 4
]]>
</screen>
</example>
@@ -314,7 +315,7 @@ PHP Parse error: Invalid body indentation level (expecting an indentation level
<example>
<title>Unterschiedliche Einrückung für den Bezeichner, der den Textkörper (Leerzeichen) schließt</title>
<programlisting role="php">
<programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php
// Der gesamte folgende Code funktioniert nicht.
@@ -345,7 +346,7 @@ PHP Parse error: Invalid body indentation level (expecting an indentation level
&example.outputs.73;
<screen>
<![CDATA[
PHP Parse error: Invalid indentation - tabs and spaces cannot be mixed in example.php line 8
Parse error: Invalid indentation - tabs and spaces cannot be mixed in example.php line 8
]]>
</screen>
</example>
@@ -407,7 +408,7 @@ END, 'd e f'];
&example.outputs.73;
<screen>
<![CDATA[
PHP Parse error: syntax error, unexpected identifier "ING", expecting "]" in example.php on line 6
Parse error: syntax error, unexpected identifier "ING", expecting "]" in example.php on line 5
]]>
</screen>
</example>
@@ -560,7 +561,7 @@ EOD
<example>
<title>Verwendung von Heredoc zur Initialisierung von statischen Werten</title>
<programlisting role="php">
<programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php
// Statische Variablen
@@ -693,7 +694,7 @@ Dies sollte ein großes 'A' ausgeben: \x41]]>
<example>
<title>Beispiel für statische Daten</title>
<programlisting role="php">
<programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php
class foo {
@@ -739,7 +740,8 @@ EOT;
darauf folgenden Zeichen, die in einem Variablennamen verwendet werden
können, als solche interpretiert und ersetzt.
</simpara>
<informalexample>
<example>
<title>String-Interpolation</title>
<programlisting role="php">
<![CDATA[
<?php
@@ -756,7 +758,7 @@ echo "He drank some $juice juice." . PHP_EOL;
He drank some apple juice.
]]>
</screen>
</informalexample>
</example>
<simpara>
Formal ist die Struktur für die grundlegende Syntax der Ersetzung von
@@ -960,11 +962,11 @@ Die Änderung des Zeichens an Index -3 auf o ergibt strong.
verdeutlichen:
</simpara>
<informalexample>
<example>
<title>Syntax mit geschweiften Klammern</title>
<programlisting role="php">
<![CDATA[
<?php
const DATA_KEY = 'const-key';
$great = 'fantastisch';
$arr = [
@@ -1021,7 +1023,7 @@ echo "C:\\directory\\{$great}.txt";
?>
]]>
</programlisting>
</informalexample>
</example>
<note>
<simpara>
@@ -1104,18 +1106,21 @@ echo "C:\\directory\\{$great}.txt";
// Ermitteln des ersten Zeichens eines Strings.
$str = 'Das ist ein Test.';
$first = $str[0];
var_dump($first);
// Ermitteln des dritten Zeichens eines Strings.
$third = $str[2];
var_dump($third);
// Ermitteln das letzten Zeichens eines Strings.
$str = 'Das ist immer noch ein Test.';
$last = $str[strlen($str)-1];
var_dump($last);
// Ändern des letzten Zeichens eines Strings.
$str = 'Look at the sea';
$str[strlen($str)-1] = 'e';
var_dump($str);
?>
]]>
</programlisting>
@@ -1127,42 +1132,44 @@ $str[strlen($str)-1] = 'e';
</para>
<example>
<!-- TODO Update for PHP 8.0 -->
<title>Beispiel für unzulässige String-Offsets</title>
<programlisting role="php">
<![CDATA[
<?php
$str = 'abc';
var_dump($str['1']);
var_dump(isset($str['1']));
$keys = [ '1', '1.0', 'x', '1x' ];
var_dump($str['1.0']);
var_dump(isset($str['1.0']));
foreach ($keys as $keyToTry) {
var_dump(isset($str[$keyToTry]));
var_dump($str['x']);
var_dump(isset($str['x']));
try {
var_dump($str[$keyToTry]);
} catch (TypeError $e) {
echo $e->getMessage(), PHP_EOL;
}
var_dump($str['1x']);
var_dump(isset($str['1x']));
echo PHP_EOL;
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
string(1) "b"
bool(true)
Warning: Illegal string offset '1.0' in /tmp/t.php on line 7
string(1) "b"
bool(false)
Cannot access offset of type string on string
bool(false)
Cannot access offset of type string on string
bool(false)
Warning: Illegal string offset 'x' in /tmp/t.php on line 9
string(1) "a"
bool(false)
Warning: Illegal string offset "1x" in Standard input code on line 10
string(1) "b"
bool(false)
]]>
</screen>
</example>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 22583751fbfdaa3eaa41aeb6470d1343f5cb2c78 Maintainer: samesch Status: ready -->
<!-- EN-Revision: e587d0655e426f97b3fcb431453da5030e743b23 Maintainer: samesch Status: ready -->
<!-- Reviewed: no -->
<sect1 xml:id="language.types.type-juggling">
<title>Typumwandlung (Typen-Jonglage)</title>
@@ -306,16 +306,19 @@ true --> 1 // bool kompatibel mit int
Klammern vor den umzuwandelnden Wert geschrieben wird.
</simpara>
<informalexample>
<example>
<title>Typumwandlung</title>
<programlisting role="php">
<![CDATA[
<?php
$foo = 10; // $foo ist ein Integer
$bar = (bool) $foo; // $bar ist ein Boolean
$foo = 10; // $foo ist ein Integer
$bar = (bool) $foo; // $bar ist ein Boolean
var_dump($bar);
?>
]]>
</programlisting>
</informalexample>
</example>
<simpara>
Folgende Umwandlungen sind erlaubt:
@@ -402,14 +405,14 @@ $binary = b"binary string";
</informalexample>
<!-- TODO Remove or move into string context section? -->
<note>
<simpara>
Anstatt eine Variable in einen <type>String</type> umzuwandeln, kann die
Variable auch in doppelte Anführungszeichen gesetzt werden.
</simpara>
<simpara>
Anstatt eine Variable in einen <type>String</type> umzuwandeln, kann die
Variable auch in doppelte Anführungszeichen gesetzt werden.
</simpara>
<informalexample>
<programlisting role="php">
<example>
<title>Verschiedene Casting-Mechanismen</title>
<programlisting role="php">
<![CDATA[
<?php
$foo = 10; // $foo ist eine ganze Zahl
@@ -418,13 +421,12 @@ $fst = (string) $foo; // $fst ist ebenfalls eine Zeichenkette
// Dies gibt aus "sie sind identisch"
if ($fst === $str) {
echo "sie sind identisch";
echo "sie sind identisch", PHP_EOL;
}
?>
]]>
</programlisting>
</informalexample>
</note>
</programlisting>
</example>
<para>
In den folgenden Abschnitten wird beschrieben, was genau passiert, wenn
@@ -449,7 +451,8 @@ if ($fst === $str) {
folgende Beispiel für alle PHP-Versionen:
</simpara>
<informalexample>
<example>
<title>Verwenden des Array-Offsets bei einer Zeichenkette</title>
<programlisting role="php">
<![CDATA[
<?php
@@ -459,7 +462,7 @@ echo $a; // bar
?>
]]>
</programlisting>
</informalexample>
</example>
<simpara>
Weitere Informationen sind im Abschnitt