• Ian Random (unregistered)

    For a professional situation, yes that is bad. But if you are surrounded by non-programmers that will see it, then the original code would be clearer.

  • nelson_no_nose (unregistered) in reply to Valczir
    Valczir:
    åäö:
    Non-php coder here. Doesn't take any real php knowledge to see that it is bad, but could someone post a proper way to do the same?

    Use python.

    That's not to say that other languages wouldn't fit the bill; python would just be my choice. But PHP really is just stupid about a lot of things. Most of it is an unintuitive mess.

    There are a few things wrong with PHP but I would not call it unintuitive. The functions and their names are a bit inconsistent but the manual compensates for that nicely and keep in mind that many of those wrap C libraries inheriting from them so in a way it is intuitive depending what language you are coming from. One of the problems with PHP is that it doesn't give you much rope to hang yourself with but lowers the bar to those who don't need much rope anyway.

    How intuitive someone might find PHP is something I would put down more to subjective experience than to the nature of that language its self. If you're talking about something where you can look at some code and quickly work it out, PHP is no Perl (too much magic), objective C (worlds ugliest syntax), C++ (operator overriding), etc. In some ways PHP is to Perl what Java is to C++. I would say that python syntax, while more expressive, is far more complex and unintuitive by its nature than PHP's.

    Since you weren't able to provide an example in python however, I don't believe your opinion is valid.

  • nelson_no_nose (unregistered) in reply to Kasper

    PHP sometimes has behaviour based on typeof input.

    Same: str_replace('what', 'with', 'inthis') str_replace(array('what'), array('with'), 'inthis')

    It's very obvious and intuitive to any programmer with a basic understanding of interpreted languages and performance issues.

    In this case, it's very likely this is for performance. Think about it. Underneath the function is running natively rather than interpreted.

    str_replace is very commonly used in PHP so in this case it makes sense to apply such an optimisation. For people used to using languages that require strict prototypes for calls and types this is really the only confusing thing in PHP, type juggling and loose/runtime/dynamic handling of function parameters.

  • With You On This One (unregistered) in reply to Evo

    +1, especially since mb_encode_numericentity appears to be taking a string with special characters and encoding them as Ӓ style escapes, where the original code took named HTML entities and turned them into special characters.

  • Powerslave (unregistered) in reply to phihag

    html_entity_decode()

Leave a comment on “Known Bad Code”

Log In or post as a guest

Replying to comment #:

« Return to Article