note 87263 added to function.date-create

From: Date: Thu, 27 Nov 2008 00:12:06 +0000
Subject: note 87263 added to function.date-create
Groups: php.notes 
Request: Send a blank email to php-notes+get-147017@lists.php.net to get a copy of this message
An interesting note that came from the tutorial (as well as my own testing) is that the DateTime constructor is exception happy. In other languages this is a bit of a no-no - throwing exceptions from within a constructor can cause all sorts of odd problems! Either way, because of this you should attempt to catch any exception and only use the object if it does not throw an exception. <?php $bad_date_string = 'ublingah!'; try { $dt = new DateTime($bad_date_string); } catch(Exception $e) { // catches 'Failed to parse time string (ublingah!) at position 0 (u)' exception. // don't use this object } ?> ---- Server IP: 202.89.58.1 Probable Submitter: 125.236.219.141 ---- Manual Page -- http://www.php.net/manual/en/function.date-create.php Edit -- https://master.php.net/note/edit/87263 Del: integrated -- https://master.php.net/note/delete/87263/integrated Del: useless -- https://master.php.net/note/delete/87263/useless Del: bad code -- https://master.php.net/note/delete/87263/bad+code Del: spam -- https://master.php.net/note/delete/87263/spam Del: non-english -- https://master.php.net/note/delete/87263/non-english Del: in docs -- https://master.php.net/note/delete/87263/in+docs Del: other reasons-- https://master.php.net/note/delete/87263 Reject -- https://master.php.net/note/reject/87263 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#147017) next »