« first day (3942 days earlier)      last day (999 days later) » 

9:54 AM
Hello folks, I don't like the following approach for validating and throwing an exception. However, I just want to ask if this a good practice or bad if I see it in a project:
class ABC {
  public function test() {
     $this->someOtherClass->validate(someRequest);
 }
}

class SomeOtherClass {
   public function validate(someRequest) {
    throw SomeExceptionBecauseOfInvalidRequest;
}
}
What I would prefer is just to get back the errors in ABC class and then throw exception there but rather straightly from the validate method
 
A validate method should not throw an exception if the validation fails. However, if the validation cannot be performed due to other reasons then it should throw the exception then and there
 
10:25 AM
@Dharman Other reasons like?
 
It depends on your validation. If there are some dependencies that cannot be met then your code needs to throw an exception
An exception should be thrown if your code encounters a situation that should is unexpected.
It should not be used to control the flow of your application logic
 
Could you please just give me a simple practical example
?
 
of what?
 
@Dharman for this
class SomeValidator {
 public function validate(someRequest) {
      // expecting some validation
     return result;
 }
}
What could be unexpected in this class?
 
See this dummy example:
<?php

class SomeValidator
{
public function validateUserHasPermission(User $user, string $permission): bool
{
$permissions = Permissions::getAll();
if (!in_array($permission, $permissions, true)) {
throw new PermissionNotFoundException();
}
return in_array($permission, $user->getPermissions(), true);
}
}
 
10:36 AM
@Dharman Perfect, thanks
 
11:22 AM
Hi, this is probably not the place to ask this, but I think this is a pretty simple question but I can't figure out the right search terms to search this.

I have a query like this :
SELECT * FROM table WHERE column LIKE IN (val1, val2, val3, ...)

How can I return the matching LIKE clause with the query itself ? like this :

SELECT *, (val1 or val2 or val3- the matched val) FROM table WHERE column LIKE IN (val1, val2, val3, ...)
Oh, and the val1, val2 and val3s would be a wildcard match "val1%". Hence why I need to get which val did it match
 
12:27 PM
Have asked this as a question: stackoverflow.com/questions/68610241/…
 
1:12 PM
@BasheerKharoti regarding throwing exceptions, this is a good read phpopendocs.com/learning/best_practice_exceptions
 
 
1 hour later…
2:41 PM
Incredibly wrong and stupid note is highly ranked on time() docs ・ Website problem ・ #81319
 
No where within the comment does it specify UTC
 
@Tiffany God I hate time
 
I linked that awhile back, Derick said he could add a few fallacies to that list...
 
3:00 PM
everyone should just use unix time
 
cmb
@Tiffany but time() always yields UTC timestamps. Still, UTC has leap seconds, so the comment is not wrong. And wrt. the time example #1, the comment is spot on.
 
On that note, happy 1627830065 everyone.
 
Would the fix be to revise the first example to make it clear that UTC can have leap seconds?
Would need to search for a day that has leap seconds, if so... not sure if that is the preferred fix though
 
cmb
3:17 PM
@Tiffany the date() is the problem, since that works on the default timezone. gmdate() would alleviate this, but still the example is somewhat suboptimal.
 
3:33 PM
 
If it ever happens, some programmer is going to find a way to either a) find a way to tidally lock that planet, so it doesn't have any days at all, or b) change the rotation of that planet so it lines up exactly with earth
 
Except when we colonize more than one planet...
 
Redefine time to some inter-stellar arbitrary basic physics value, then define Earth time in terms of that.and Mars time in terms of that.
 
I had this conversation a few weeks ago, time IS already the interstellar arbitrary physics value, it's also the mechanism which almost all other values are derived. Change the length of a second, you have to change almost everything else, 1kg is no longer 1kg etc
The problem is days
 
 
2 hours later…
5:53 PM
Isnt' time defined by movement? E.g. the earth's orbit around the sun.
Btw, 1kg is defined by a clump in France. ;)
1m is defined in relation to speed of light in vacuum.
Why can't I respond to myself in this stupid chat...? Grrr.
Time can also be defined in atom half-lifes, not sure it is tho.
At least speed of light isn't arbitrary. Or perhaps it is, but at least it stays the same. Or perhaps it doesn't, but so far as we know. ^^
clump = lump
 
6:18 PM
@OlleHärstedt that's the old definition
 
6:41 PM
Missing arginfo warning get_info and get_contents ・ uploadprogress ・ #81320
 
6:52 PM
@Tiffany you can, but you have to copy/paste the message ID. Also since the numbers are incremented by one, in theory, you can respond to yourself in the future...if you're fast.
 
 
3 hours later…
9:30 PM
incorrect image on save ・ *Graphics related ・ #81321
 
10:07 PM
@Tiffany Ah, thanks.
 
10:27 PM
this is why closing tags are important web.archive.org/web/20140310190221/http://…
 

« first day (3942 days earlier)      last day (999 days later) »