Re: Scalar type hinting

From: Date: Mon, 27 Feb 2012 22:54:38 +0000
Subject: Re: Scalar type hinting
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
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?




Thread (163 messages)

« previous php.internals (#58213) next »