Use of @ to hide error is not poetry
I’ve been wrestling with an install of WordPress. While phpmyadmin works, WordPress has been silently dying. No errors in either the Apache log, the MySQL log, or anywhere else for that matter.
I finally tracked it down to
Fatal error: Call to undefined function: mysql_connect() in /data/www/admin.untyped.com-ssl/wordpress/wp-includes/wp-db.php on line 27
Now, this is clearly some oddity in my own server. However, what bothers me most is that this error was thrown by this line of code:
$this->dbh = @mysql_connect($dbhost,$dbuser,$dbpassword);
in the file wp-db.php. What upsets me, in terms of coding practice, is the abuse of the ‘@’ symbol here. My WordPress install was dying silently, without any notification being left anywhere, as to why it was dying.
Good programming practice deals with errors. Poetic code would not simply hide these errors; it would trap for possible problems, and report them in a reasonable manner.
Something to consider for future versions: handle errors gracefully. Especially the likely error conditions, like whether or not MySQL is properly configured, or whether the database can be accessed.
Thanks for listening.
- The topic ‘Use of @ to hide error is not poetry’ is closed to new replies.