4 ms·
PHP functions you (probably) never use
- mootothemax 17y agoTo be honest, the only time I've seen glob() used was with an outsourced code bomb that was written to delete all the code if a get variable (think it was delete_everything) was passed, presumably in case we didn't pay up. We paid, and surprisingly didn't choose to ask for any more work from that particular coder ;) I like the example of sys_getloadavg(), but am unsure if I'd ever use it...
- streety 17y agoAgreed on sys_getloadavg(), by the time you get to PHP much of the overhead of serving the connection has already been incurred.
- pvg 17y agoIt's also a poor way to decide whether to stop serving pages. Depending on circumstances, it's possible for request handling to be still reasonable or completely wedged for same load numbers. The number is also dependent on the configuration of the machine so moving to a box with, say, more cores might make whatever magic constant threshold you put in your code even wronger.
- middus 17y agoWas the contractor from Kerbleckistanian? ;) http://thedailywtf.com/Articles/Maybe-I-Needing-Later.aspx http://thedailywtf.com/Articles/Maybe-I-Needing-Later.aspx
- mootothemax 17y agoDear god, is this a common occurrence?
- pilif 17y agoI would recommend direly against using the gettext extension and _() because these imply setlocale and setlocale, when called from a PHP script has some side effects: For one, it changes the locale per process. Now I know that PHP isn't totally thread save (actually it is - the extensions - like gettext grin are the problem), but imagine apache in a threaded MPM and setlocale being called from different scripts. Then, setlocale() alters how certain library functions work. *printf() for example uses the number formatting settings of the current locale. If the libraries you are using are not aware of locale settings, they might fail in interesting ways once you set the locale to something that uses, say, a comma as the decimal separator. And last but not least, if you change your language file, you will have to restart the web server which generally isn't needed with PHP otherwise. Wordpress has actually reimplemented portions of gettext so it works with the .mo files, but it doesn't alter the locale of the web server process. And for regional formatting of numbers and dates, we got the intl extension with 5.3 which does just that, also not interfering with the web server process, other libraries and PHP itself.
- louislouis 17y agoWish I knew about debug_print_backtrace() earlier. It could've saved me so much time debugging other peoples scripts!
- robryan 17y agoNever knew levenshtein was in there, just wrote my own function for it when I needed it.
- ohashi 17y agoMe either. Very nifty for searches in case the user typo'd something.
- ErrantX 17y agoI've use quite a few of those but: sys_getloadavg() Is a new one for me. And actually really awesome because I can integrate it into a current project!!
- hackermom 17y ago$binary_cksum = md5( $data, true ); i guess the author should try step into 2004 and php5...
- duairc 17y agoI also like date_sunset and date_sunrise.
- encoderer 17y agoI was writing code not long ago to determine if a given day is a holiday. I didn't want to use a database of dates that would have to be updated in the future. I was breezing along with the variable-date holidays like Thanksgiving, and then I came to Easter. Turns out, it's slightly complex. It has to do with moon cycles. After wigging out a little about this task, an afterthought that should've been easy, I googled for the specific formula so I could begin to express it in code. (I had already done a 20, 30 minute search for an existing PHP Class to handle all dates and was unsuccessful.) What I found next nearly blew my mind. http://php.net/manual/en/function.easter-date.php http://php.net/manual/en/function.easter-date.php This at once delighted and disgusted me. A perfect example of the utility AND horror of PHP's large standard library.
- pilif 17y agoso because PHP, a language designed to make building web applications easier, disgusts you because it has a built-in function that facilitates a task which is often needed in web applications? And you think this is inferior to other languages where you would have to write that yourself or pick one of dozens of unofficial implementations with bugs unknown to you? One could blame PHP for not having namespaces, but certainly not for providing official implementations for often-used pieces of functionality (though in case of easter_date? How many functions with different functionality do you come up with that you would like to give the same name?) (edit: I'm not trying to troll here. OP has said he was "disgusted" by the presence of easter_date and from that I was inferring that he would prefer PHP not to have easter_date, thus my assertion of PHP being "inferior" to other languages that lack easter_date. By no means did I want to sound rude just a bit cynical maybe. I apologize for that.)
- encoderer 17y agoDown, boy. Inferior? I never said it was inferior. Seems you're arguing against somebody, but not me.
- pilif 17y agowell. I inferred "inferior" from the fact that you were "disgusted" (your word) by the presence of an easter_date function. I assumed that you would not be disgusted about other languages that don't provide the function. If one is disgusted by one thing and not by another, it's IMHO save to assume that the non-disgusting one is superior to the disgusting one. If I have misunderstood you, I apologize.
- qeorge 17y agoI'm embarrassed to admit I thought _() was specific to Wordpress. Great to know its not. metaphone() is a great tip too. I've only used soundex() in MySQL, will be interesting to see how they compare.
- pilif 17y agodon't use the built-in _(). See my comment below.