Re: Scalar type hinting

From: Date: Mon, 27 Feb 2012 19:05:10 +0000
Subject: Re: Scalar type hinting
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On Mon, February 27, 2012 10:45 am, Ángel González wrote:
> On 27/02/12 17:19, Richard Lynch wrote:
>> PRESUMPTION:
>>
>> *ANY* strict datatype could also be NULL, to represent a failure
>> condition...
>>
>> Otherwise, when you are out of RAM:
>> strict $o = new Object(); //violates strict, because Object HAS to
>> be
>> NULL, as there is no RAM left for it to be an object.
> Uh? No. You would get a fatal error because PHP exceeded maximum
> allowed memory.

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...

-- 
brain cancer update:
http://richardlynch.blogspot.com/search/label/brain%20tumor
Donate:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FS9NLTNEEKWBE




Thread (163 messages)

« previous php.internals (#58172) next »