note 112983 added to datetime.settime
| From: | MichaelWhite | Date: | Wed, 14 Aug 2013 20:37:26 +0000 |
| Subject: | note 112983 added to datetime.settime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-195968@lists.php.net to get a copy of this message | ||
Unfortunately it's a bit late to really do anything about this for this class but I feel
compelled to help prevent this in the future.
When writing an interface that you intend to be chainable, do not ever return anything other than
the object instance. Returning an object instance when things run properly and returning false when
an error occurs only exacerbates the error because now it will hit a fatal error where it cannot
call such and such a method on a non-object (i.e. the value of false that just got returned b/c of a
soft error) and now you end up with a broken script.
Worse is that the error appears to be with the code calling a function on a non-object when the real
error is somewhat earlier and partially unrelated to that call.
Systems that are designed as chainable should handle error reporting in one of the following ways:
1) If the error is severe enough, just throw an exception. The calling code can handle that and the
error message and details will be far more clear as to the source of why the error occurred than
returning false and ending up with a function called on a non-object error message.
2) If the error is not severe and would not cause a crash or complete failure, log that error within
the class and provide mechanisms to later check for any errors and get details on what those are.
For example, create a property to store an array of error data and then create one or more methods
that allow access to that data, such as getLastError() or getLastErrorCode() and
getLastErrorMessage() and getAllErrors().
----
Server IP: 69.147.83.199
Probable Submitter: 66.216.209.133
----
Manual Page -- http://php.net/manual/en/datetime.settime.php
Edit -- https://master.php.net/note/edit/112983
Del: integrated -- https://master.php.net/note/delete/112983/integrated
Del: useless -- https://master.php.net/note/delete/112983/useless
Del: bad code -- https://master.php.net/note/delete/112983/bad+code
Del: spam -- https://master.php.net/note/delete/112983/spam
Del: non-english -- https://master.php.net/note/delete/112983/non-english
Del: in docs -- https://master.php.net/note/delete/112983/in+docs
Del: other reasons-- https://master.php.net/note/delete/112983
Reject -- https://master.php.net/note/reject/112983
Search -- https://master.php.net/manage/user-notes.php