• (nodebb)
    iif is a common convention in VB, Excel, and Cold Fusion. That gives us a sense of this developer's background, and the fact that they want to force it into a language where you've already got constructs for inline ifs.

    The string mangling functions make it look like their background (or misguided desire) is functional programming. But then their reimplementation of functions that already exist just makes it look like they're stupid.

    Oh, and maybe frist?

  • (nodebb)

    If an implementation does something different it is not a re-invention.....

  • (nodebb)

    Where does str2int turn into a busy loop? The invariant is $i++, and it will eventually stop once $i is $length. Or am I overlooking something?

  • Sauron (unregistered)

    The HDD which stores the repository of that legacy code should immediately be thrown into a bonfire, around which the devs should dance to celebrate the purging of their codebase and to exorcise the demons of bad code.

  • akozakie (unregistered)

    Nah, skip the date functions. The fact that they exist in the code is WTF enough.

  • Yikes (unregistered)

    C'mon! Everyone knows it's faster to recode features from other languages than to RTFM!

  • Barry Margolin (github)

    singlequote() is useful for things like array_map('singlequote', $array);. Although it's likely that this is being used when substituting into a SQL query, and you should use prepared statements instead.

  • MRAB (unregistered) in reply to Melissa U

    @Melissa U: When $concat_flag becomes false, neither of the conditions can be true, so it's pointless to continue looping. The smart thing to do would be to break out of the loop.

  • Argle (unregistered)

    I want to weep just because this is so effing common.

  • Fromeo (unregistered)

    I don’t know how PHP does ternaries, but I think the iif function is going to evaluate both $a and $b regardless of the condition, whereas a bare ternary (in other languages) would only evaluate one or the other. So you can’t use it for short-circuit evaluation.

  • (nodebb) in reply to Barry Margolin

    Little Bobby Tables ( https://xkcd.com/327/ ) was my first thought when I saw the single quote function as well.

  • (nodebb)

    The iif might not be the programmer's background but the code's. Perhaps some sort of auto translator?

  • Jonas (unregistered)

    Remember that php ternaries are evaluated right-to-left unlike in other languages, meaning that the iif fiction might actually behave more as expected. Unless lazy evaluation is expected, as another poster points out.

  • (nodebb) in reply to Fromeo

    But iif uses a ternary. Why would PHP evaluate both arguments just because the ternary is wrapped in a function?

    You know what, I will only be somewhat surprised if it does.

    Addendum 2022-10-13 13:48: EDIT: ah you know what, I guess they will be evaluated before being passed into the function.

    If this matters, that's even more WTF.

Leave a comment on “An Explosion of Strings”

Log In or post as a guest

Replying to comment #:

« Return to Article