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: 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
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: 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: 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: 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
article thumbnail

CodeSOD: Query the Contract Status

The Daily WTF

There's a PHP front end, which also talks directly to the database, as well as a Java backend, which also talks to point-of-sale terminals. The PHP front end has code that looks like this: $sql = "select query from table where id=X" ; $result = mysql_query ( $sql ); //. Rui recently pulled an all-nighter on a new contract.

PHP 64
article thumbnail

CodeSOD: Holiday Sample Pack

The Daily WTF

On the other hand, submitter Born 2 Ruby, Forced 2 PHP was hired to work on a Ruby on Rails application, but after starting, discovered that the RoR app was an aspiration and the day to day work was to keep the legacy PHP application from falling over in production. Advertisement]. Keep the plebs out of prod. Learn more.

PHP 98