5
m4lik
3y

Today I've read this line of code:
$like === true ? $operator = "LIKE" : $operator = "=";

Should I be angry, sad or disappointed?
That was written by a person who I tought could code.

Comments
  • 0
    Btw: this is from an open source project. Would be interesting to know if anyone can find out wich it's from.
    (It has more than 500 stars on github and more than 200 forks. so it should be possible to find out)
  • 0
    So they are using an inline if to determine a database query to be a like or not.

    Nothing new here other then the inline IF about to make me throw something at this code 😠
  • 1
    @C0D4 the problem is not only that he used a ternary operator. But 2 other things: 1. He used it wrong, and 2. He used it NOT inline but as a single line.
  • 0
    @m4lik that’s what I meant 😂 had a blank moment.

    Ternaries drive me up the wall, when I come across them.
    Granted they take up “less” space but you loose so much context due to them as you have to decipher a simple if/else to ? : and pray it does what it should.
  • 0
    @C0D4 I have to say I like ternaries tbh. But only for very simple things like $type = $isMaster ? "slaves" : "all".
  • 0
    Dude, it's PHP what did you expect?

    jk
Add Comment