article thumbnail

CodeSOD: PHP Error Logging

The Daily WTF

Today's anonymous submitter sends us some PHP exception logging code. This particular code shows a surprising understanding of some clever PHP tricks. They opted to use var_dump , a handy PHP debugging function which dumps an object's properties to the output buffer. Unfortunately, everything about it is still wrong.

PHP 56
article thumbnail

CodeSOD: Metaception

The Daily WTF

But if you're using PHP and JavaScript, there's good odds that someone you work with has decided to combine these two tastes together to create something nobody wants to taste. > We start with some HTML which wraps some PHP code. A more extreme version happened to our anonymous submitter. closest ( "tr" ).

PHP 64
Insiders

Sign Up for our Newsletter

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

article thumbnail

CodeSOD: A Poorly Pruned Branch

The Daily WTF

Juliano had this very non-WTF bit of PHP code: if (! " [Advertisement] Otter - Provision your servers automatically without ever needing to log-in to a command prompt. I usually (but not always) avoid using those as WTFs. path && false) { //disabling this branch because X instead. But no, we did none of that.

article thumbnail

CodeSOD: Monthly Totals

The Daily WTF

Daniel spotted an array called $months in a PHP application. Advertisement] Continuously monitor your servers for configuration changes, and report when there's configuration drift. The data being stored in the array was some total of the sales of some commodity, for the past 5 months. That much all made sense.

PHP 107
article thumbnail

CodeSOD: Underscoring the Importance of Good Naming

The Daily WTF

Martin 's team had a problem in PHP. Being PHP, the empty function also doesn't check for empty strings, it checks for strings that can coerce to false (which includes the empty string, but also includes '0' ). See, the is_null function is, well, checking for nulls. It isn't checking for empty strings.

PHP 103
article thumbnail

CodeSOD: To Tell the Truth

The Daily WTF

So many languages eschew "truth" for "truthiness" Today, we're looking at PHP's approach. PHP automatically coerces types to a boolean with some fairly simple rules: the boolean false is false the integer 0 is false, as is the float 0.0 In pure PHP, anything non-zero is true, but here only 1 is true.

PHP 64
article thumbnail

CodeSOD: Sorts of Dates

The Daily WTF

Unrelated to this code, but a PHP weirdness, we pass the callable cmp as a string to the usort function to apply a sort. Every time I write a PHP article, I learn a new horror of the language, and "strings as callable objects" is definitely horrifying. Now, a moment ago, I said that we knew the format of the inputs.

PHP 60