breez
breez

Reputation: 75

Best practice: handle class error

Is it at all possible to have a class return false instead of an object reference? It would make error handling very clean. Consider the code:

$page = new PageContent('www.google.com');
if ($page)
  // do stuff
else
  // handle error

Upvotes: 2

Views: 165

Answers (1)

Ben James
Ben James

Reputation: 125147

No. But you can throw an exception in the __construct() method, and handle that.

Upvotes: 5

Related Questions