Support » Requests and Feedback » 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/ 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.

Viewing 1 replies (of 1 total)
  • The coding practice is actually good practice for a website deployment, however I’ve gone and written my own error-handler system that catches and displays errors at the end of the page when an admin is logged in.
    You don’t want potential wacky errors spit out all over your page — you want them collected for later display/logging, or as you said ‘handled’ appropriately for the user (such as CG-Amazon displaying “No Products Found”, instead of spitting out the fact that the XML parser code got a 503 error response from Amazon…)

Viewing 1 replies (of 1 total)
  • The topic ‘Use of @ to hide error is not poetry’ is closed to new replies.