On Tue, Jun 1, 2010 at 8:43 PM, Stas Malyshev <smalys...@sugarcrm.com>wrote:

> Hi!
>
>
>  type hinting for arrays and objects does the same (catchable fatal error
>> on mismatch), whats the difference?
>>
> > if you start using a piece of code, which uses type hinting for
> > non-scalar variables, you already have to deal with this kind of
> > situation (custom error handler, or catching the exception)
>
> The difference is it is very rare that you pass object of one class instead
> of another, and it is usually an obvious mistake (like using wrong variable,
> etc.). It is very frequent that you want number and get "1" instead - almost
> all incoming data for PHP are strings.


Occasionally, I used to forget, that my arrays get converted object if I
jsonize them back and forth, and sometimes I forget, that my fetched mysql
row is an array or an object, but maybe thats me.
But I agree with you, so I also think, that we should go for the weak type
hinting with scalars.


> So you may get by with basically ignoring class types since you'd almost
> never would have to handle failure in your app. With scalar strict typing,
> you'd most certainly have to handle failures.
>

I think that with weak type hinting, the only cases, when you should get an
error/exception is when you pass a scalar, which cannot be converted to the
hinted type('123abc' hinted as an int, or 1.3 hinted as an int)

Also, it never makes sense to convert one object type into another, and
> almost never this operation can be defined.


array and ArrayObject?


> On the other hand, scalar types are very frequently converted in PHP and
> generally considered rather interchangeable in other dynamic languages.
> Nobody would refuse to understand that IS_INTEGER:0 and IS_BOOL:0 is the
> same and mean "false". If you make your application have this distinction,
> you'd have to code for it in a way that never was what PHP is about.
>
>
Agree, we are used to it.


>
>  So from my point of view, you are arguing against the type hinting
>> itself, which is too late IMHO.
>>
>
> No it is not too late. It is never too late to stop PHP from turning into
> Java wannabe. If you want strictly-typed exclusively-OO language, you know
> where to find them.
>
>
I mean it's too late to argue about that the current type hinting triggers
an error in case of type mismatch.
My previous mail was about that we shouldn't implement the weak type hinting
to allow silent truncation on type conversion.

Tyrael

Reply via email to