2012-04-13 11 views
3

Hilfe Fix diese FehlerFatal error: abgefangene Ausnahme 'Exception' with message ‚Datetime ::

Fatal error: Uncaught exception 'Exception' with message 'DateTime::_construct() [datetime.--construct]: Failed to parse time string (--) at position 0 (-): Unexpected character' in Z:\home\plati\www\view.php:110 Stack trace: #0 Z:\home\plati\www\view.php(110): DateTime->_construct('--') #1 {main} thrown in Z:\home\plati\www\view.php on line 110

$newday = $a['dayz']; 
$endmonth = $a['monthz']; 
$newyear = $a['yearz']; 
$date = new DateTime("$newyear-$endmonth-$newday"); 
$date->modify('+8 day'); 
$year = $date->format('Y'); 
$month = $date->format('m'); 
$day = $date->format('d'); 

Antwort

1

help fix this error

Sie leicht mit der Ausnahme, es durch den Fang umgehen kann, wird dies den Fehler in dem Sinne beheben, die Sie brauchen, um über diesen Fehler nicht zu stören mehr:

try { 
    $newday = $a['dayz']; 
    $endmonth = $a['monthz']; 
    $newyear = $a['yearz']; 
    $date = new DateTime("$newyear-$endmonth-$newday"); 
    $date->modify('+8 day'); 
    $year = $date->format('Y'); 
    $month = $date->format('m'); 
    $day = $date->format('d'); 
} catch(Exception $e) { 
    # do nothing 
} 

zumindest auf Irgendwann müssen Sie die Fehlerbehandlung durchführen. Ausnahmen erfordern dies, DateTime löst Ausnahmen aus.

4

Haben Sie jemals "$newyear-$endmonth-$newday" den Wert Druck versucht? Aufgrund des Fehlers sieht es so aus, als wären die Variablen nicht mit irgendeinem Inhalt gefüllt. Also poste bitte das Ergebnis dieser Zeichenfolge.

1

Die Werte in $ a sind leer; Überprüfe deine Eingaben.

+0

oh ja $ a ist leer tyvm –

Verwandte Themen