On 14 Jul 2014, at 14:12, Alexey Zakhlestin <[email protected]> wrote:
> I don’t think that "scalar casts” should do any additional error-catching.
> they target a very different usecase.
> It shouldn’t guarantee correctness of the whole program. It should guarantee
> that variable types are fixed inside of function.
That is exactly what is being proposed though. People (including Anthony
himself, along with other proposals) have previously suggested type hints which
just casted. However, I don’t think this is terribly useful. You can already do
that really easily (`$foo = (int)$foo;`), and it’s too lenient; the non-scalar
type hints are useful because they validate your types, and the scalar ones,
while casting, should validate to a degree.
> In my opinion, this patch should act 100% similar to zpp.
> And if, at some later point zpp-behaviour changes similar change should
> happen to userland "scalar casts”
Keeping close to zpp would be nice, but zpp’s behaviour isn’t always the most
sensible and useful one, but we should try to keep somewhat close to it.
> Some people talk about inconsistency, which is introduced by reusing same
> syntax for "strict parameter types" and "scalar parameter casts”. There’s
> some truth there.
> Let’s use different syntax.
>
> This might work:
>
> function foo((int) $a)
> {
> var_dump($a);
> }
>
> I would read it as declaration-level casting
That has already been proposed. That is not this proposal. I’d suggest you read
back in this thread; I’ve previously explained my issues with just casting with
no validation, pure strict type hints, why it’s fine to reüse the syntax, and
linked to Nikita Popov’s blog post on the subject.
--
Andrea Faulds
http://ajf.me/
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php