Voll Upload SGD Fachinformatiker PHP
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
$meinevariable = 42;
|
||||
|
||||
echo $meinevariable . "<br>";
|
||||
|
||||
$mienevariable = 55; //<-- Dort ist der Fehler!
|
||||
|
||||
echo $meinevariable . "<br>";
|
||||
?>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
//Code3.8
|
||||
echo $teiler;// Kontrollausgabe
|
||||
$a = $b / $teiler;// vermutete Fehlerstelle
|
||||
echo "Nach dem vermuteten Fehler";
|
||||
|
||||
//Code4.1 TryCatch Block zur Auffangen einer Ausnahme
|
||||
|
||||
try {
|
||||
[kritische Anweisung(en)]
|
||||
}
|
||||
catch ([Ausnahme]) {
|
||||
[Maßnahmen für den Ausnahmefall]
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
if (isset($_GET['a']) && isset($_GET['b'])) {
|
||||
$a = $_GET['a'];
|
||||
$b = $_GET['b'];
|
||||
echo "Versuch der Division zweier Zahlen.<br>" . "Werfen einer Ausnahme, " . "wenn Division durch 0 zu teilen.<hr> ";
|
||||
try {
|
||||
|
||||
if ($b == 0)
|
||||
throw new Exception("<hr>Keine Division durch 0 erlaubt<hr>");
|
||||
echo $a / $b . "<br>";
|
||||
} catch(Exception $e) {
|
||||
print_r($e);
|
||||
}
|
||||
|
||||
echo "<hr>Nach dem potenziellen Problem. ";
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<form >
|
||||
Wert 1: <input name="a"><br>
|
||||
Wert 2: <input name="b"><br>
|
||||
<input type="submit">
|
||||
</form>
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
class MeineException1 extends Exception {}
|
||||
|
||||
class MeineException2 extends Exception {}
|
||||
|
||||
if (isset($_GET['a'])) {
|
||||
|
||||
$a = $_GET['a'];
|
||||
|
||||
try {
|
||||
if ($a == 0) {
|
||||
throw new Exception("<hr>Standardausnahme<hr>");
|
||||
} else if ($a < 0) {
|
||||
throw new MeineException1("<hr>Klein<hr>");
|
||||
} else {
|
||||
throw new MeineException2("<hr>Gross<hr>");
|
||||
}
|
||||
|
||||
} catch(MeineException1 $e) {
|
||||
echo($e -> getFile());
|
||||
} catch(MeineException2 $e) {
|
||||
echo($e -> getLine());
|
||||
} catch(Exception $e) {
|
||||
echo($e -> getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<form >
|
||||
|
||||
Wert : <input name="a"><br>
|
||||
|
||||
<input type="submit">
|
||||
|
||||
</form>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
$i = 42;
|
||||
|
||||
echo "Vor dem Problem. Wert von \$i: $i" . "<hr>";
|
||||
|
||||
for ($i == 0; $i < 10 ; $i++) {
|
||||
echo "Hochzählen von \$i: $i" . "<br>";
|
||||
}
|
||||
|
||||
echo "Nach dem Problem. Wert von \$i: $i" . "";
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
echo "Ein Parse Error wird erzeugt: " . "<hr>";
|
||||
echo "ein schließendes Anführungszeichen fehlt;
|
||||
echo "<hr>Nach dem Problem. ";
|
||||
?>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
echo "Ein Fatal Error wird provoziert:" . "<hr>";
|
||||
gibtEsNicht();
|
||||
echo "<hr>Nach dem Problem. ";
|
||||
?>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
echo "Eine Warnung wird provoziert:" . "<hr>";
|
||||
echo $nichtAngelegt . "<br>";
|
||||
echo "Ein fataler Fehler wird provoziert:" . "<hr>";
|
||||
echo "a" / "b" . "<br>";
|
||||
?>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
echo "Eine Warnung wird provoziert:" . "<hr>";
|
||||
echo $nichtAngelegt . "<br>";
|
||||
$fehler=error_get_last();
|
||||
error_log($fehler['message'],3, "fehler.log");
|
||||
?>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
echo "Aktueller Error-Level: " . error_reporting()
|
||||
. "<br>";
|
||||
error_reporting(E_ERROR);
|
||||
echo "Neuer Error-Level: " . error_reporting()
|
||||
. "<br>";
|
||||
echo "Eine Warnung wird provoziert:" . "<hr>";
|
||||
echo $nichtAngelegt . "<br>";
|
||||
echo "Ein Fehler wird provoziert:" . "<hr>";
|
||||
echo "a" / "b" . "<br>";
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
echo "Aktueller Error-Level: " . error_reporting(). "<br>";
|
||||
echo "Eine Wanung wird provoziert:" . "<br>";
|
||||
echo @$nichtAngelegt . "<br>";
|
||||
echo "Ein Fehler wird provoziert:" . "<hr>";
|
||||
echo @("a" / "b") . "<br>";
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
// Fehlerbehandlungsfunktion
|
||||
|
||||
function meinErrorCallback($fehlercode, $fehlertext,
|
||||
$fehlerdatei, $fehlerzeile) {
|
||||
echo "Eigene Behandlung! Fehlercode: " . $fehlercode
|
||||
. ", Fehlertext: " . $fehlertext . "<br>";
|
||||
}
|
||||
|
||||
// benutzerdefinierte Fehlerbehandlung
|
||||
|
||||
set_error_handler("meinErrorCallback");
|
||||
echo "Eine Warnung wird provoziert:" . "<hr>";
|
||||
echo $nichtAngelegt . "<br>";
|
||||
echo "<hr>Nach dem 1. Problem.<hr>";
|
||||
echo "Ein fataler Fehler wird provoziert:" . "<hr>";
|
||||
gibtEsNicht();
|
||||
echo "<hr>Nach dem 2. Problem.<hr>";
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user