Hi,

On Thu, Jan 15, 2015 at 7:13 PM, Andrea Faulds <a...@ajf.me> wrote:
>
>>  Now from that perspective I cannot rely that I am in strict and would have 
>> to handle the default weak even although I declared in my class that i 
>> wanted strict mode which only affected the code inside of that file.  That's 
>> ultimately what I am saying and why I am stating it would have to handle 
>> both conditions.  In reality, you'd always act as if you were in a weak mode 
>> supporting that case.
>
> I… really don’t understand, I’m sorry. Are you complaining that if a caller 
> uses the weak mode, they are not bound by strict types? Why do you want to 
> affect the code of the caller?

Consider this badly designed API:

    declare(strict_typehints=TRUE);

    const MODE_APPEND = 0;
    const MODE_TRUNCATE = 1;
    const MODE_PREPEND = 2;

    function write_file(string $path, int $mode, string $data)
    {
        // it's quite obvious
    }

Somewhere else, you forget the parameters order ...

    declare(strict_typehints=FALSE);

    $path = '/important/file.dat';
    $data = '1 year';
    $mode = MODE_APPEND;

    write_file($path, $data, $mode);

It's a bad example - an awful (and indeed, very much useless) API,
combined with an absent-minded consumer. Yet, it demonstrates how
putting the caller in control *can* cause a disaster.

Of course, it is fair to say that this would be a very rare case,
where it is the author's fault for both being bad at design and
relying on a type-hinting feature that they don't understand, but it
is also fair to say that it is possible that a lot of people assume
that "strict_typehint=TRUE" affects definitions instead of calls (I
know I would, if I wasn't following this list).

But anyway, the point is - if you can't rely on it, why use it at all?
I guess if your goal was to use strict typing as a debugging tool
here, it makes *some* sense, but otherwise the way it works is
completely inverted.

----

What I would suggest is the '(type) $weak' vs 'type $strict' syntax
that was already mentioned.

I've said this before, during the previous RFCs discussions - all of
these proposals will fail, because they all suggest using the 'type
$whatever' syntax and that automatically upsets the "other camp",
whichever it is, but especially if the "other camp" is supporters of
strict typing. That's the moment when they become opposition, while
they could've otherwise not care because it's simply not their
"battle". If both are proposed to co-exist in a clean way (instead of
via a switch), I believe that we'll get substantially more positive
opinions from both sides.

And to hell with the "consistency" argument. Since when did PHP become
*that* concerned about purity and high consistency levels? Call this a
speculation, but barely a few people care for the the internal
functions' behavior - most of us will be happy if they stay as is
regardless of the kind of type-hinting that gets adopted. What we want
is the features (plural!), not the philosophy.

</rant>

Cheers,
Andrey.

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

Reply via email to