note 112983 rejected from datetime.settime by googleguy

From: Date: Wed, 14 Aug 2013 21:09:59 +0000
Subject: note 112983 rejected from datetime.settime by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-195970@lists.php.net to get a copy of this message
Note Submitter: Michael White ---- 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().

« previous php.notes (#195970) next »