0

Sometimes functions fail to do what they say they do. When this happens, some functions throw an exception (e.g. PDO constructor) and others just return (e.g. mysql_connect would return false).

I have many times had to choose between one of these approaches over the other and I wonder if there is a design principle that deals with this.

Emanuil Rusev
  • 34,563
  • 55
  • 137
  • 201

1 Answers1

2

Returning false on error is considered to be an old practice, today, it's considered a bad one.

mysql_connect is a very old (2002) functions, before PHP implemented Exceptions or an OOP interface.

PDO is a newer, more recent (and more recommended) interface for accessing the database, and as such, it throws errors in the form of PDOExceptions.

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308