11
coda
7y

$a = 1;
$b = 2;
echo ($a < $b) ? ($a > $b) ? 'This is totally fine' : ($a < $b) ? 'This is not ok!' : 'Perfect' : 'No problem here';

Why do people do this?!

(And I mean nested ternary ifs, not coding in PHP :P)

Comments
  • 1
  • 2
    @inaba I have to disagree! It’s just not very readable. There’s no point in making code look cryptic for the sake of saving a few keystrokes.
  • 1
    @irene because why not?
  • 0
    @irene I know right? Why would someone code in a language that most websites on the internet are coded in?! Madness!
  • 0
    @irene and... which language is „better”?
  • 1
    @mlask than php? Pretty much all other languages
  • -1
    @inaba and why do you think like that? The fact you don’t know PHP doesn’t mean that every other language is better ;)
  • 1
    @mlask M8 I know php. Did it for like 3 years before I saw the light.

    I took a vocational education called webintegrator where I did php
  • 0
    @inaba so... that means, you really know nothing about PHP - can you even tell, what’s wrong with it and why other are better?

    @irene be more specific - why they’re better?
  • 1
    @mlask the syntax is shit.
    There's like 5 different cases.

    mysql_escape_string and mysqli_real_esape_string. (Also, use prepared statements and PDO for the love of God)
    sleep, usleep, nanosleep
    Sometimes the errors would never make any sense
    Allowing people to mix HTML and php code makes for some really annoying spaghetti.
    Sometimes the order of parameters is inconsistent between functions
    Anonymous functions aren't well designed
    Then there's the rapid community of people insisting PHP is the best language with no faults
    WordPress and the fact that a majority of PHP jobs are WordPress

    That's what I can think of of the top of my head from my mobile

    edit
    -------------

    Also this error: http://sandbox.onlinephpfunctions.com/...
  • 0
    @inaba what’s wrong with that error? You miss off a semi colon and so it doesn’t expect the if. The error message explains exactly what’s wrong.
  • 1
    @inaba I agree, that syntax and inconsistency is - sometime - pain in the ass when coding in php. On the other side, it’s quite easy to learn, easy to deploy, fast and library independent. For other languages you’ll easily find lib for everything - which makes coding more like building with lego, without creative thinking, and also making code dependent on someone’s other code... Again - everyone should use whatever likes and knows the most.
  • 0
    @coda it doesn't really say what the problem is

    @mlask Plenty of other languages are easy to lean and easy to deploy. Library independent doesn't mean much when the libraries you use are solid, and open source. Just like you're dependend on some libraries with other languages, you're depended on Zend for the PHP library. It's pretty much the same shit as with building with legoes
  • 1
    @inaba it tells you EXACTLY what’s wrong. It’s not expecting an if statement to appear where it did.

    It can’t tell you you’re missing a semi colon because there are plenty of other symbols that are valid after your statement.

    In fact I’m not sure I’ve ever seen an error message that says “missing semi colon on line x” for any language.
  • 1
    Y'all need prettier in your life. Even nested tenaries gets readable with it.

    Still a valid point. Why the fuck. And I must ask what y'all talking of php, i only see Perl.
  • 2
    Please please please enclose your ternaries in parentheses!

    It's an unreadable mess otherwise.
Add Comment