On 11/11/2020 20:20, David Rodrigues wrote:
I have been asked by a friend if declare(strict_types=1) will be applied by
default for some version of PHP, like 9.x or will it be always required by
all scripts forever. Someone can tell me?
If yes, what is the reason for requiring it? Why it can't be the default
behavior (or maybe, the unique behavior).
The question (which I hear often) misunderstands the original intent of
the declaration, as I understand it: the strict_types switch was not
designed as a transition mechanism for old code, it was designed as a
genuine choice between two different options, both equally new.
Before PHP 7.0, there was no ability for a (user-defined) function to
declare that it wanted an int, string, float, or boolean argument. When
it was proposed that these "scalar type hints" be added, there were
different, strongly held, opinions on how that should work, leading to
at least 5 separate RFCs, several thousand mailing list posts, and a lot
of general unhappiness.
The idea behind the strict_types directive was to combine two versions
of the feature into one system, allowing users to switch between them at
will. The proposal made clear that both modes have their advantages and
disadvantages. A few of those were affected by compatibility with older
code - in particular, around the behaviour of built-in functions - but
those were not the main driving factors behind providing two modes.
Perhaps, 5 or 6 years on, things have changed. Certainly, there are a
vocal community of users who see "strict_types=1" as unreservedly
"better" in some fundamental way - but then, there always were, that's
why the debate was so heated. I rather suspect that most of the
arguments put forward for one position or the other then are just as
true now.
I do wonder if people would even be asking the question, if the modes
had been named something like "scalar_types=coerce" and
"scalar_types=error", and somehow arranged such that neither was in
force by default.
[PS: What a beautifully timed e-mail - "11/11/2020 20:20 UTC"!]
Regards,
--
Rowan Tommins (né Collins)
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php