NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP 5 Throwing Exceptions in Constructors

George Schlossnagle george at omniti.com
Wed Feb 9 21:36:39 EST 2005


On Feb 9, 2005, at 9:33 PM, Ophir Prusak wrote:

> Hi Hans,
>
> I was dealing with this exact same dilemma on a project I'm currently 
> coding.
> We ending up going with Adam's option B: move the code which can fail
> to outside the constructor.
>
> In the original design the you could create an object where the
> constructor could read some information from a database.
>
> In the final design, we moved the database code to a new load()
> function that executes the actual database call. This does add an
> additional step, but having the constructor throw an execution just
> messes things up.

This is a best practice in many OO languages (for instance c++)

George




More information about the talk mailing list