On Fri, Mar 10, 2017 at 4:20 PM, Rowan Collins <rowan.coll...@gmail.com> wrote:
> On 10 March 2017 10:57:42 GMT+00:00, Andrey Andreev <n...@devilix.net> wrote:
>>I'm not really interested in making "strict mode" less strict - it's
>>already opt-in and non-enforceable.
>>I want ways to write stonger-type code in "non-strict mode", because
>>the fact that "strict mode" is non-enforceable means I can never rely
>>on it.
>
> This is a common misconception - you can absolutely rely on strict mode 
> enforcing your contract.
>
> Basically all that happens in non-strict mode is that if the caller writes:
>
> foo($value);
>
> The compiler automatically changes that to:
>
> foo((string)$value);
>
> (That's not literally how it's implemented, but it's the effect you get.)
>

If I want to enforce strict_types=1 operation on the caller - I can't,
it can always be overriden, and thus I can never rely on it.
The fact that strict_types=0 will do casting for me has no relation to this.

If there's any misconception here, it is that both modes are equal -
if they were, we wouldn't have 2 of them.

> As the receiver of that parameter, you can't tell, and don't care, if it was 
> the human writing the code who added the cast, or the compiler adding it for 
> them.
>

You don't, but I do care at times.
I want to know that the *caller* gave me what I want, and that the
compiler didn't modify it before I received it.

Why I may care about that is a different question, and nototiously
hard to explain to people who don't, as all you'd always say something
like "you asked for an integer and got an integer" ...
Let's say I asked for one of 3 class constants, that happen to hold
integer values, and you gave me a string that just happens to be
castable to one of those values - you obviously aren't using my API
correctly, but I have no way of telling you this because the compiled
hid it from both of us.

These cases may be rare and very specific, but they do exist and are
valid. Yet for some reason, very few people around here want to admit
that - all in the name of keeping PHP a weakly-typed language all the
way. As if adding one feature would all of a sudden change your
ability to write the same code you always did.

Sorry about the rant, you can probably tell this irritates me a lot
and I can't help it. I'll shut up now, just don't go on a mission to
convince me otherwise - won't ever work.

> You can't detect someone blindly writing "(string)" everywhere any more than 
> you can detect whether they are running in strict mode. Nor can you know if 
> they took it straight from unfiltered user input, or copy-pasted a literal 
> string to 10 different files, or a hundred other things you'd really like 
> them not to do. All you know is, you asked for a string, and you got one.
>

... exactly - uncertainty all over the place. :)

Cheers,
Andrey.

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

Reply via email to