- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
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.
Admin
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.
Admin
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.
Admin
+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.
Admin
html_entity_decode()