On 27/02/12 20:05, Richard Lynch wrote:
> You are correct.
>
> I'd have to come up with some OTHER scenario not involving fatal
> error, such as:
>
> strict $db = new DB();
>
> and your database being down, unavailable, or connection parameters
> being wrong.
>
> The principle remains.
>
> You probably still want $db to be NULL in that situation, rather than
> an unusable DB object.
>
> Otherwise, you'll have to write a lot more sanity checking code
> elsewhere, which is what you are trying to avoid in the first place...
>
> Or, perhaps not.
>
> Perhaps you really do want this case to just plain bomb out with a
> failure that the $db is not strictly an object, with no recourse to
> try again, or deal with the error in application logic...
It could be throwing an exception.
You usually want it to be just what you want. In some cases you may
want to accept NULLs. You should provide a different qualifier in that
case, such as "strict?"

Yes, you may end up with things like

nullable strict DB $db = DB::factory();


which doesn't look like PHP at all. But I suppose that's what you wanted?



-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to