Code: Select all
if (!$this->validation->maxLength($this->username, $this->usernameMaxLength)) {
$this->pushError('Your username cannot be longer than ' . $this->usernameMaxLength . ' characters');
}Moderator: General Moderators
Code: Select all
if (!$this->validation->maxLength($this->username, $this->usernameMaxLength)) {
$this->pushError('Your username cannot be longer than ' . $this->usernameMaxLength . ' characters');
}IMO OOP certainly makes more readble code. Referring to things as objects with properties and methods sort of makes you think more about how the code actually works.astions wrote:Well, I've been writting classes the last week and have finally gotten a pretty solid grasp on it. I know someone will have me beat on this one, but this is the craziest 3 lines of code I have ever written. It does look pretty cool though heh. 2 months ago I would have saw this and been like![]()
Code: Select all
if (!$this->validation->maxLength($this->username, $this->usernameMaxLength)) { $this->pushError('Your username cannot be longer than ' . $this->usernameMaxLength . ' characters'); }
Yes, exactly. When you see something like:d11wtq wrote:IMO OOP certainly makes more readble code. Referring to things as objects with properties and methods sort of makes you think more about how the code actually works.
Code: Select all
if ($validator->length($data))
{
// more process
}Why? I know that if you used Java a lot that is what you would do, but I don't see the point of throwing Exceptions all around the place with no insight to possible error clauses. What he is checking for is bool, if the subclass didn't exist, then yeah, I would try an exception to let the developer know that a run time error occurred where there was no subclass to access.feyd wrote:I'd use an exception. ;)
Well, for one, he's talking about OOP. Exceptions are better equipt for doing what he wishes in OOP. Exceptions will also allow you to break out of the functional block in more simple terms to a central location to handle the error as the lines of where they are handled are often quite clear.santosj wrote:Why? I know that if you used Java a lot that is what you would do, but I don't see the point of throwing Exceptions all around the place with no insight to possible error clauses. What he is checking for is bool, if the subclass didn't exist, then yeah, I would try an exception to let the developer know that a run time error occurred where there was no subclass to access.
So for example:feyd wrote:Well, for one, he's talking about OOP. Exceptions are better equipt for doing what he wishes in OOP. Exceptions will also allow you to break out of the functional block in more simple terms to a central location to handle the error as the lines of where they are handled are often quite clear.
The original post has little, if anything, to do with subclassing. There are other factors to consider as well: it can be an interesting challenge to support multiple languages in a single build. I personally use Exceptions to easily build localized versions of error outputs; not as multiple duplicates of the same exception with differing text embedded, but as centralized locations to pull up the localized strings. All categorized and neatly kept so all the errors are simple to alter and with simple subclassing to segment errors into differing categories internally -- FatalExceptions and RecoverableExceptions for instance.
Code: Select all
try {
$this->validation->maxLength($this->username, $this->usernameMaxLength);
} catch(InvalidUsernameLengthException $e) {
throw $e;
}Man, I wrote my message before that, but it is pretty coincidental.astions wrote:What would that look like? Are you saying use try/catch? Have an example?
http://www.zend.com/php5/articles/php5-exceptions.phpastions wrote:What would that look like? Are you saying use try/catch? Have an example?