Hi!

Currently if you pass int(42) to an array type hint it will fail. For
the "weak type hint" it will cast it to whatever was hinted.

This makes sense. 42 doesn't have array representation. We might introduce a rule that if anything passed to a function that requires array gets converted to one-element array, but that's our discretion, depending on use cases.

This is inconsistent with our current userland (array) casting, where
(array)42 ends up being array(42);

Explicit casting may not be the same as implicit. In explicit casting the intent of the user is, well, explicit, so we can afford more drastic changes than in implicit case.

And same with passing an array(42) to a boolean hint, which with the
(bool) cast returns bool(true).
And what if I pass int(42) to boolean hint? Its an obvious dataloss,
should that trigger a warning message or fail?

How it's a data loss? You want to know if it's boolean-ly true or false, not keep the whole int. It's like saying calling strlen is a "data loss" because of the whole string it keeps only length. That's exactly what you wanted it to do!

The edgecases for the "weak type hinting" are way to many and
inconsistent with the rest of our casting structure, so adding more

That's not "edge cases", that's just the cases where we have to define language behavior as it makes sense. "Consistency" for the sake of everything doing the same even if it makes no sense is bullshit. And so far the only case is arrays - which *are* different from scalars, so expecting that they work the same is baseless. Different types have different properties.

I want the "strict type hinting" because it is consistent with the
current type hinting implementation, and I don't have to deal with any

Current implementation is for objects. Objects work differently from scalar types. Pretending they are the same for "consistency" makes absolutely zero sense.
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

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

Reply via email to