# Coercive Scalar Type Hints RFC

- Thread: https://externals.io/message/83405
- Original archive: https://news-web.php.net/php.internals/83405
- Started by Zeev Suraski on 2015-02-21T17:22:08+00:00
- Messages: 81
- RFC: Deprecate type juggling to and from bool type within the function type juggling context (Declined) — https://externals.io/rfc/deprecate-function-bool-type-juggling.md
- RFC: Coercive Scalar Type Hints (Declined) — https://externals.io/rfc/coercive_sth.md
- Page 1 of 4: messages 1 to 25 (25 per page, add `?page=N` to the URL)
- Next page: https://externals.io/message/83405.md?page=2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #83405 — Zeev Suraski — 2015-02-21T17:22:08+00:00

URL: https://externals.io/message/83405#83405

All,



I’ve been working with François and several other people from internals@
and the PHP community to create a single-mode Scalar Type Hints proposal.



I think it’s the RFC is a bit premature and could benefit from a bit more
time, but given the time pressure, as well as the fact that a not fully
compatible subset of that RFC was published and has people already
discussing it, it made the most sense to publish it sooner rather than
later.



The RFC is available here:



wiki.php.net/rfc/coercive_sth



Comments welcome!


Zeev

---

## #83407 — Pierre Joye — 2015-02-21T17:46:10+00:00

URL: https://externals.io/message/83405#83407 · In reply to: #83405

hi,


> All,
>
>
>
> I’ve been working with François and several other people from internals@
> and the PHP community to create a single-mode Scalar Type Hints proposal.
>
>
>
> I think it’s the RFC is a bit premature and could benefit from a bit more
> time, but given the time pressure, as well as the fact that a not fully
> compatible subset of that RFC was published and has people already
> discussing it, it made the most sense to publish it sooner rather than
> later.

This does not provide what I consider as the best compromise. An
optional per file/package strict mode and a fully compatible with
existing mode.

However here are some comments:

Integer STH (int):
“42.0” should not be accepted. This is a float not an integer. It
introduces edge cases I would rather avoid (precision setting f.e.,
imagine "42.000001" or "42.0001"?)

Boolean STH (bool):
this is by far too weak. How strings could be consider as valid, how?
"true" > Boolean true? I suppose then "false" will be boolean false?
What's is the boolean value of float 0.5?
At the very least only integer should be accepted, 0 > false, anything >=1 true

Changes to Internal Functions:
I am generally speaking against changing them by default, this is a
too big BC break.

This RFC is also not complete. A test should be provided to valid the
changes against existing applications. I suspect the impact may not be
as small as we think. I can be wrong here but tests will tell me how
wrong I could be :)

And finally, this RFC only proposes one solution, so competitive RFCs
are still required to actually represent alternatives.

Cheers,
Pierre

---

## #83412 — Anthony Ferrara — 2015-02-21T18:12:26+00:00

URL: https://externals.io/message/83405#83412 · In reply to: #83405

Zeev,

First off, thanks for putting forward a proposal. I look forward to a
patch that can be experimented with.

There are a few concerns that I have about the proposal however:

> Proponents of Strict STH cite numerous advantages, primarily around code safety/security. In their view, the conversion rules proposed by Dynamic STH can easily allow ‘garbage’ input to be silently converted into arguments that the callee will accept – but that may, in many cases, hide difficult-to-find bugs or otherwise result in unexpected behavior.

I think that's partially mis-stating the concern. It's less about
"garbage input" and more about unpredictable behavior. You can't look
at code and know that it will not produce an error with dynamic
typing. That's one of the big advantages of strict typing that many
people want. In reality the reasons are complex, varied and important
to each person.

> Proponents of Dynamic STH bring up consistency with the rest of the language, including some fundamental type-juggling aspects that have been key tenets of PHP since its inception. Strict STH, in their view, is inconsistent with these tenets.

Dynamic STH is apparently consistency with the rest of the language's
treatment of scalar types. It's inconsistent with the rest of the
languages treatment of parameters.

However there's an important point to make here: a lot of best
practice has been pushing against the way PHP treats scalar types in
certain cases. Specifically around == vs === and using strict
comparison mode in in_array, etc.

So while it appears consistent with the rest of PHP, it only does so
if you ignore a large part of both the language and the way it's
commonly used.

In reality, the only thing PHP's type system is consistent at is being
inconsistent.



In the "Changes To Internal Functions" section, I think all three
types are significantly flawed:

1. "Just Do It" - This is problematic because a very large chunk of
code that worked in 5.x will all of a sudden not work in 7.0. This
will likely create a python 2/3 issue, as it would require a LOT of
code to be changed to make it compatible.

2. "Emit E_DEPRECATED" - This is problematic because raising errors
(even if suppressed) is not cheap. And the potential for raising one
for a non-trivial percentage of every native function call has the
potential to have a MASSIVE performance impact for code designed for
5.x. Without a patch to test, it can't really be codified, but it
would be a shame to lose the performance gains made with 7 because
we're triggering 100's, 1000's or 10000's of errors in a single
application run...

3. "Just Do It but give users an option to not" - This has the
problems that `E_DEPRECATED` has, but it also gets us back to having
fundamental code behavior controlled by an INI setting, which for a
very long time this community has generally seen as a bad thing
(especially for portability and code re-use).



Moving along,

> Further, the two sets can cause the same functions to behave differently depending on where they're being called

I think that's misleading. The functions will always behave the same.
The difference is how you get data into the function. The behavior
difference is in your code, not the end function.

> For example, a “32” (string) value coming back from an integer column in a database table, would not be accepted as valid input for a function expecting an integer.

There's an important point to consider here. You're relying on
information outside of the program to determine program correctness.
So to say "coming back from an integer column" requires concrete
knowledge and information that you can't possibly have in the program.
What happens when some DBA changes the column type to a string type.
The data will still work for a while, but then suddenly break without
warning when a non-integer value comes in. Because the
value-information comes from outside.

With strict mode, you'd have to embed a cast (smart or explicit) to
convert to an integer at the point the data comes in. So semantic
information about the value is places right at the point of entry
(forcing the code to be more explicit and clear).

Additionally, with the dual-mode proposal DB interactions can be in
weak mode and have the exact behavior you're describing here. Giving
the user the choice, rather than making assumptions.

> Strict zval.type based STH effectively eliminates this behavior, moving the burden of worrying about type conversion to the user.

Correct. And you say that as if it's a bad thing. Being explicit about
type conversions isn't what you'd do in a 10 line-of-code script where
you can realize what the types are by just thinking about it. But on
large scale systems exposing the type conversions to the user gives
the power to actually understand the codebase when you can't fit the
whole thing in your head at the same time.

So what you cite here as a disadvantage many consider to be an advantage.

> Performance

I find it funny how the non-strict crowd keeps bringing up performance...

> It is our position that there is no difference at all between strict and coercive typing in terms of potential future AOT/JIT development - none at all

So really what you're saying is that you disagree with me publicly. A
statement which I said on the side, and I said should not impact RFC
or voting in any way. And is in no part in my RFC at all. Yet brought
up again.

> Static Analysis. It is the position of several Strict STH proponents that Strict STH can help static analysis in certain cases. For the same reasons mentioned above about JIT, we don't believe that is the case

This is patently false. Keep not believing it all you want, but
*static analysis* requires statically looking at code. Which means you
have no value information. So static analysis can't possibly happen in
cases where you need to know about value information (because it's not
there). Yes, at function entry you know the types. But static analysis
isn't about analyzing a single function (in fact, that's the least
interesting case). It's more about analyzing a series of functions, a
function call graph. And in that case strict typing (based only on
type) does make a big difference.



In short, I think the concerns around the handling of internal
functions is significant enough to cause major concern about this
proposal.

Thanks

Anthony


> All,
>
>
>
> I’ve been working with François and several other people from internals@
> and the PHP community to create a single-mode Scalar Type Hints proposal.
>
>
>
> I think it’s the RFC is a bit premature and could benefit from a bit more
> time, but given the time pressure, as well as the fact that a not fully
> compatible subset of that RFC was published and has people already
> discussing it, it made the most sense to publish it sooner rather than
> later.
>
>
>
> The RFC is available here:
>
>
>
> wiki.php.net/rfc/coercive_sth
>
>
>
> Comments welcome!
>
>
> Zeev

---

## #83414 — Zeev Suraski — 2015-02-21T18:13:52+00:00

URL: https://externals.io/message/83405#83414 · In reply to: #83412

> -----Original Message-----
> From: Anthony Ferrara [mailto:ircmaxell@gmail.com]
> Sent: Saturday, February 21, 2015 8:12 PM
> To: Zeev Suraski
> Cc: PHP internals
> Subject: Re: [PHP-DEV] Coercive Scalar Type Hints RFC
>
> Zeev,
>
> First off, thanks for putting forward a proposal. I look forward to a
> patch
> that can be experimented with.
>
> There are a few concerns that I have about the proposal however:
>
> > […]
> safety/security. In their view, the conversion rules proposed by Dynamic
> STH
> can easily allow ‘garbage’ input to be silently converted into arguments
> that
> the callee will accept – but that may, in many cases, hide
> difficult-to-find
> bugs or otherwise result in unexpected behavior.
>
> I think that's partially mis-stating the concern.

I don't think it is, based
It's less about "garbage input"
> and more about unpredictable behavior. You can't look at code and know
> that it will not produce an error with dynamic typing. That's one of the
> big
> advantages of strict typing that many people want. In reality the reasons
> are
> complex, varied and important to each person.



>
> > […]
> language, including some fundamental type-juggling aspects that have been
> key tenets of PHP since its inception. Strict STH, in their view, is
> inconsistent
> with these tenets.
>
> Dynamic STH is apparently consistency with the rest of the language's
> treatment of scalar types. It's inconsistent with the rest of the
> languages
> treatment of parameters.
>
> However there's an important point to make here: a lot of best practice
> has
> been pushing against the way PHP treats scalar types in certain cases.
> Specifically around == vs === and using strict comparison mode in
> in_array,
> etc.
>
> So while it appears consistent with the rest of PHP, it only does so if
> you
> ignore a large part of both the language and the way it's commonly used.
>
> In reality, the only thing PHP's type system is consistent at is being
> inconsistent.
>
>
>
> In the "Changes To Internal Functions" section, I think all three types
> are
> significantly flawed:
>
> 1. "Just Do It" - This is problematic because a very large chunk of code
> that
> worked in 5.x will all of a sudden not work in 7.0. This will likely
> create a
> python 2/3 issue, as it would require a LOT of code to be changed to make
> it
> compatible.
>
> 2. "Emit E_DEPRECATED" - This is problematic because raising errors (even
> if
> suppressed) is not cheap. And the potential for raising one for a
> non-trivial
> percentage of every native function call has the potential to have a
> MASSIVE
> performance impact for code designed for 5.x. Without a patch to test, it
> can't really be codified, but it would be a shame to lose the performance
> gains made with 7 because we're triggering 100's, 1000's or 10000's of
> errors
> in a single application run...
>
> 3. "Just Do It but give users an option to not" - This has the problems
> that
> `E_DEPRECATED` has, but it also gets us back to having fundamental code
> behavior controlled by an INI setting, which for a very long time this
> community has generally seen as a bad thing (especially for portability
> and
> code re-use).
>
>
>
> Moving along,
>
> > […]
>
> I think that's misleading. The functions will always behave the same.
> The difference is how you get data into the function. The behavior
> difference
> is in your code, not the end function.
>
> > […]
> database table, would not be accepted as valid input for a function
> expecting
> an integer.
>
> There's an important point to consider here. You're relying on information
> outside of the program to determine program correctness.
> So to say "coming back from an integer column" requires concrete
> knowledge and information that you can't possibly have in the program.
> What happens when some DBA changes the column type to a string type.
> The data will still work for a while, but then suddenly break without
> warning
> when a non-integer value comes in. Because the value-information comes
> from outside.
>
> With strict mode, you'd have to embed a cast (smart or explicit) to
> convert to
> an integer at the point the data comes in. So semantic information about
> the
> value is places right at the point of entry (forcing the code to be more
> explicit
> and clear).
>
> Additionally, with the dual-mode proposal DB interactions can be in weak
> mode and have the exact behavior you're describing here. Giving the user
> the
> choice, rather than making assumptions.
>
> > […]
> burden of worrying about type conversion to the user.
>
> Correct. And you say that as if it's a bad thing. Being explicit about
> type
> conversions isn't what you'd do in a 10 line-of-code script where you can
> realize what the types are by just thinking about it. But on large scale
> systems
> exposing the type conversions to the user gives the power to actually
> understand the codebase when you can't fit the whole thing in your head at
> the same time.
>
> So what you cite here as a disadvantage many consider to be an advantage.
>
> > […]
>
> I find it funny how the non-strict crowd keeps bringing up performance...
>
> > […]
>
> So really what you're saying is that you disagree with me publicly. A
> statement which I said on the side, and I said should not impact RFC or
> voting
> in any way. And is in no part in my RFC at all. Yet brought up again.
>
> > […]
>
> This is patently false. Keep not believing it all you want, but *static
> analysis*
> requires statically looking at code. Which means you have no value
> information. So static analysis can't possibly happen in cases where you
> need
> to know about value information (because it's not there). Yes, at function
> entry you know the types. But static analysis isn't about analyzing a
> single
> function (in fact, that's the least interesting case). It's more about
> analyzing a
> series of functions, a function call graph. And in that case strict typing
> (based
> only on
> type) does make a big difference.
>
>
>
> In short, I think the concerns around the handling of internal functions
> is
> significant enough to cause major concern about this proposal.
>
> Thanks
>
> Anthony
>
> 
> > […]
> Hints proposal.
> > […]

---

## #83415 — Anthony Ferrara — 2015-02-21T18:28:34+00:00

URL: https://externals.io/message/83405#83415 · In reply to: #83407

Pierre,

> And finally, this RFC only proposes one solution, so competitive RFCs
> are still required to actually represent alternatives.

That is a good thing. it should only propose one solution. Making a
single RFC proposing two solutions would be a MASSIVE mistake IMHO as
these proposals are complex and charged enough without trying to make
a voter read a single piece of text that goes back and forth between
two options.

We need to be simplifying, not making more difficult. Only about 25%
of my RFC is dedicated to the proposal. The other ~75% is dedicated to
summarizing the conversation and acting as a FAQ. That could well live
off-RFC if we used discussion pages or something of the like (which we
likely should).

Anthony

---

## #83416 — Pierre Joye — 2015-02-21T18:31:52+00:00

URL: https://externals.io/message/83405#83416 · In reply to: #83415

> Pierre,
>
> > […]
>
> That is a good thing. it should only propose one solution. Making a
> single RFC proposing two solutions would be a MASSIVE mistake IMHO as
> these proposals are complex and charged enough without trying to make
> a voter read a single piece of text that goes back and forth between
> two options.
>
> We need to be simplifying, not making more difficult. Only about 25%
> of my RFC is dedicated to the proposal. The other ~75% is dedicated to
> summarizing the conversation and acting as a FAQ. That could well live
> off-RFC if we used discussion pages or something of the like (which we
> likely should).
>

I am not saying this is good or bad.

I only fear the php7-Zend like RFCs being done again with this one.
Let prevent that to happen. We need a consensus and well thought
compromises. I do not see any of that in that one.



-- 
Pierre

@pierrejoye | http://www.libgd.org

---

## #83417 — Zeev Suraski — 2015-02-21T19:11:19+00:00

URL: https://externals.io/message/83405#83417 · In reply to: #83412

Sorry for the previous prematurely sent email, looks like I found a new
keyboard shortcut :)

> -----Original Message-----
> From: Anthony Ferrara [mailto:ircmaxell@gmail.com]
> Sent: Saturday, February 21, 2015 8:12 PM
> To: Zeev Suraski
> Cc: PHP internals
> Subject: Re: [PHP-DEV] Coercive Scalar Type Hints RFC
>
> Zeev,
>
> First off, thanks for putting forward a proposal. I look forward to a
> patch
> that can be experimented with.
>
> There are a few concerns that I have about the proposal however:
>
> > […]
> safety/security. In their view, the conversion rules proposed by Dynamic
> STH
> can easily allow ‘garbage’ input to be silently converted into arguments
> that
> the callee will accept – but that may, in many cases, hide
> difficult-to-find
> bugs or otherwise result in unexpected behavior.
>
> I think that's partially mis-stating the concern.

I don't think it's mis-stating the key concern.  At least not based on what
I've heard from most people here over the last few months.

> It's less about "garbage input"
> and more about unpredictable behavior. You can't look at code and know
> that it will not produce an error with dynamic typing. That's one of the
> big
> advantages of strict typing that many people want. In reality the reasons
> are
> complex, varied and important to each person.

Your ability to look at code and know whether or not it will produce errors
is very similar in both strict and coercive typing.  But that goes back to
what we already decided to agree to disagree on - whether or not strict type
give you any tangible extra data when you look at code - aka Static
Analysis.
Note that Strict Typing would produce all the errors of coercive typing and
then some.  So knowing whether code will produce errors is arguably more
difficult in strict typing, although I think that at the end of the day,
it's pretty much equivalent.
Again, I did see Static Analysis being brought up by just a handful of
people, perhaps not even that.  For most people, it was the silent
acceptance of input that's likely to be invalid.

> > […]
> language, including some fundamental type-juggling aspects that have been
> key tenets of PHP since its inception. Strict STH, in their view, is
> inconsistent
> with these tenets.
>
> Dynamic STH is apparently consistency with the rest of the language's
> treatment of scalar types. It's inconsistent with the rest of the
> languages
> treatment of parameters.

Not in the way Andrea proposed it, IIRC.  She opted to go for consistency
with internal functions.  Either way, at the risk of being shot for talking
about spiritual things, Dynamic STH is consistent with the dynamic spirit of
PHP, even if there are some discrepancies between its rule-set and the
implicit typing rules that govern expressions.  Note that in this RFC I'm
actually suggesting a possible way forward that will align *all* aspects of
PHP, including implicit casting - and have them all governed by a single set
of rules.

> However there's an important point to make here: a lot of best practice
> has
> been pushing against the way PHP treats scalar types in certain cases.
> Specifically around == vs === and using strict comparison mode in
> in_array,
> etc.

I think you're correct on comparisons, but not so much on the rest.  Dynamic
use of scalars in expressions is still exceptionally common in PHP code.
Even with comparisons, == is still very common - and you'd use == vs. ===
depending on what you need.

> So while it appears consistent with the rest of PHP, it only does so if
> you
> ignore a large part of both the language and the way it's commonly used.

Let's agree to disagree.  That's one thing we can always agree on!  :)

> In reality, the only thing PHP's type system is consistent at is being
> inconsistent.

I'd have to partially agree with you here;  But if you read the RFC through
including its future recommendations, you'd see it's perhaps the first
attempt in 20 years to fix that.  Instead of doing that through the
introduction of a 3rd (albeit simplistic rule-set that only pays attention
to zval.type) - a creation of a single set of rules that will be consistent
across the whole language, beginning with userland and internal functions.

> In the "Changes To Internal Functions" section, I think all three types
> are
> significantly flawed:
>
> 1. "Just Do It" - This is problematic because a very large chunk of code
> that
> worked in 5.x will all of a sudden not work in 7.0. This will likely
> create a
> python 2/3 issue, as it would require a LOT of code to be changed to make
> it
> compatible.
>
> 2. "Emit E_DEPRECATED" - This is problematic because raising errors (even
> if
> suppressed) is not cheap. And the potential for raising one for a
> non-trivial
> percentage of every native function call has the potential to have a
> MASSIVE
> performance impact for code designed for 5.x. Without a patch to test, it
> can't really be codified, but it would be a shame to lose the performance
> gains made with 7 because we're triggering 100's, 1000's or 10000's of
> errors
> in a single application run...
>
> 3. "Just Do It but give users an option to not" - This has the problems
> that
> `E_DEPRECATED` has, but it also gets us back to having fundamental code
> behavior controlled by an INI setting, which for a very long time this
> community has generally seen as a bad thing (especially for portability
> and
> code re-use).

I do too, and I was upfront about their cons, not just pros.  And yet, they
all bring us to a much better outcome within a relatively short period of
time (in the lifetime of a language) than the Dual Mode will.

> > […]
>
> I think that's misleading. The functions will always behave the same.
> The difference is how you get data into the function. The behavior
> difference
> is in your code, not the end function.

I'll be happy to get a suggestion from you on how to reword that.
Ultimately, from the layman user's point of view, she'd be calling foo()
from one place and have it accept her arguments, and foo() from another
place and have it reject the very same arguments.

> > […]
> database table, would not be accepted as valid input for a function
> expecting
> an integer.
>
> There's an important point to consider here. You're relying on information
> outside of the program to determine program correctness.
> So to say "coming back from an integer column" requires concrete
> knowledge and information that you can't possibly have in the program.
> What happens when some DBA changes the column type to a string type.
> The data will still work for a while, but then suddenly break without
> warning
> when a non-integer value comes in. Because the value-information comes
> from outside.

Of course we're relying on information coming from outside, as we all know,
this is one of the most common use cases for PHP.
While theoretically you're right, in practice, in the vast majority of cases
it wouldn't play out like that.  The string column won't be tested
exclusively with "123" inputs.  As soon as there's a non-numeric-string
input, it'll fail.  That's likely to happen very early in the process, and
that's before considering that if there's such a huge mismatch between the
semantic meaning of the column and what the function expects - the problem
is likely to be found even sooner, since the function will simply not
perform its intended job.

On the flip-side, imagine that same developer using strict types.  Feeding
the function that integer in string form gets rejected.  What are her
options?  The developer is likely  to just explicitly cast the value into an
int, giving up on any and all sanitization that coercive types would offer
her, happily accepting "Apples" and "100 Dalmatians" as valid inputs.  That,
on the other hand, is a *very* likely scenario.

> With strict mode, you'd have to embed a cast (smart or explicit) to
> convert to
> an integer at the point the data comes in.

First, I'm not aware of smart/safe casts being available or proposed at this
point.
Secondly, why at the point the data comes in?  That would be ideal for
static analyzers, but it's probably a lot more common that it will be done
at the first point in time where it gets rejected.

> Additionally, with the dual-mode proposal DB interactions can be in weak
> mode and have the exact behavior you're describing here. Giving the user
> the
> choice, rather than making assumptions.

This is bound to be misquoted and used against me, but I don't think it's a
good idea to give the user the choice in such a way.  I could have sworn
that you tweeted the quote about perfection being not when there's nothing
left to add, but nothing left to remove, but perhaps it was someone else.
Either way, two modes are worse than one, if we can come up with a good
single unified mode that addresses *most* cases.

Remember you can always implement custom type checking to your heart's
content.  You can easily implement if (!is_int($foo)) { exit; } in the
not-so-common-cases where accepting "42" as 42 might be disastrous.
However, on the caller side, forcing people to clutter their code with
casts - many casts - either explicit casts or custom ones - is going to
affect a lot more developers in a lot more places.  The bang for the buck of
adding strict mode is just not there, in my humble opinion of course.


> > […]
> burden of worrying about type conversion to the user.
>
> Correct. And you say that as if it's a bad thing. Being explicit about
> type
> conversions isn't what you'd do in a 10 line-of-code script where you can
> realize what the types are by just thinking about it. But on large scale
> systems
> exposing the type conversions to the user gives the power to actually
> understand the codebase when you can't fit the whole thing in your head at
> the same time.

I have a hard time connecting to the 'power' approach.  I think developers
want their code to work, with minimal effort, and be secure.  Coercive
scalar type hints will do an excellent job at that.  Strict type hints will
be more work, are bound to a lot of trigger "Oh come on" responses, and as a
special bonus - proliferate the use of explicit casts.  Let me top that -
you'd have developers who think they're security conscious, because they're
using strict mode - with code that's full of explicit casts.


> So what you cite here as a disadvantage many consider to be an advantage.

Perhaps, but I used the proper verb at the top ("We believe").

> > […]
>
> So really what you're saying is that you disagree with me publicly. A
> statement which I said on the side, and I said should not impact RFC or
> voting
> in any way. And is in no part in my RFC at all. Yet brought up again.

We listed all what we believe to be misconceptions that were brought up on
internals.  As recently as yesterday, you had a PHP power user (Larry) that
was under the strong impression Strict STH would yield substantial
performance benefits.  Given that it was claimed in the past, and since we
can't assume every voter reads every last word that's written on internals@
threads, it was important to list that here even if it's not mentioned in
the Strict/Dual mode RFC.
It's also worth mentioning that there are people who *assume* that strict
type hints can somehow help performance, without being domain experts at
neither the engine nor JIT, even if they weren't exposed to the explicit
statements that suggested that on blogs and on internals@ - adding to the
importance of making it clear that there are no performance benefits to that
approach.

>
> > […]
>
> This is patently false.

It's actually patently true.  We don't believe that is the case.  QED.

While at it, can we stop using that 'patently false', and stick for
constructive wording such as 'I disagree'?

Also, I think that if you quoted the rest of the sentence you chose to trim,
it would appear a lot less confrontational:
"Static Analysis. It is the position of several Strict STH proponents that
Strict STH can help static analysis in certain cases. For the same reasons
mentioned above about JIT, we don't believe that is the case - ***although
it's possible that Strict Typing may be able to help static analysis in
certain edge cases.***"

That's still under 'we (don't) believe', so again, it's "patently true".
You can disagree, but that's our opinion.

I'll also add the most important part of that paragraph for the sake of
completeness:
"It is our belief that even if that is true, Static Analyzers need to be
designed for Languages, rather than Languages being designed for Static
Analyzers."

> Keep not believing it all you want, but *static analysis*
> requires statically looking at code. Which means you have no value
> information. So static analysis can't possibly happen in cases where you
> need
> to know about value information (because it's not there). Yes, at function
> entry you know the types. But static analysis isn't about analyzing a
> single
> function (in fact, that's the least interesting case). It's more about
> analyzing a
> series of functions, a function call graph. And in that case strict typing
> (based
> only on
> type) does make a big difference.

I think it's fair to say that while we were unable to convince you there's
no tangible extra value in Strict STH compared to any other kind of STH that
guarantees the type of value a function will get, you were also unable to
convince Dmitry, Stas or myself - all of which independently discussed it
with you.  Again, despite that, I'm not saying that you're "patently wrong",
just that I don't believe you're right.

Thanks for the feedback!

Zeev

---

## #83420 — padraic.brady@gmail.com — 2015-02-21T19:56:08+00:00

URL: https://externals.io/message/83405#83420 · In reply to: #83414

> > […]
>
> I don't think it is, based

The sentence stresses garbage in too much to read as accurate. To
clarify, there is a) garbage in due to weak coercion and b) a function
being called with a string when the typehint says int. Both are
separate concerns around error detection. Stricter coercion can enable
only one of these two, for example. That's better than neither, of
course! The coercion rules were stricter than I expected based on
previous emails. Stressing one too much might suggest to a reader that
the second concern does not exist.

Other pedantic comment: "numerous" is probably too strong a word
there. The advantages may vary by person, but usually fit within basic
five-finger math. It would be more important to enumerate them rather
than selecting one as primary.

On the RFC rules themselves, a few comments:

1. Happy to see leading/trailing spaces excluded.
2. Rules don't make mention of leading zeroes, e.g. 0003
3. "1E07" might be construed as overly generous assuming we are
excluding stringy integers like hex, oct and binary
4. I'm assuming the stringy ints are rejected?
5. Is ".32" coerced to float or only "0.32"? Merely for clarification.
6. Boolean coercion from other types... Not entirely sure myself.
Completely off the cuff: <=0: false, >0:true, floats and strings need
not apply.
7. In string to float, only capital E or also small e?
8. I'll never stop call them "stringy" ints.


Paddy

--
Pádraic Brady

http://blog.astrumfutura.com
http://www.survivethedeepend.com

---

## #83422 — Anthony Ferrara — 2015-02-21T20:07:46+00:00

URL: https://externals.io/message/83405#83422 · In reply to: #83417

Zeev,

I won't nit-pick every point, but there are a few I think need to be clarified.

> > […]
>
> Not in the way Andrea proposed it, IIRC.  She opted to go for consistency
> with internal functions.  Either way, at the risk of being shot for talking
> about spiritual things, Dynamic STH is consistent with the dynamic spirit of
> PHP, even if there are some discrepancies between its rule-set and the
> implicit typing rules that govern expressions.  Note that in this RFC I'm
> actually suggesting a possible way forward that will align *all* aspects of
> PHP, including implicit casting - and have them all governed by a single set
> of rules.

The point I was making up to there is that we currently have 2 type
systems: user-land object and ZPP-scalar. So in any given function you
have 2 type systems interacting. The current ZPP scalar type is
dynamic, and user-land object static.

With the proposal here, you'd unify user-land scalar to behave as
zpp-scalar. So you'd have two type systems in any given function:
scalar and object (which behave differently).

My proposal gives you the same two by default (scalar and object) and
a strict switch to collapse them into a single, unified type system.

This is even more apparent with the int-float acceptance, because we
can mentally model Float as an object that extends Int. Then it makes
perfect sense why you'd accept ints where you see floats, but not the
opposite.

> > […]
>
> I think you're correct on comparisons, but not so much on the rest.  Dynamic
> use of scalars in expressions is still exceptionally common in PHP code.
> Even with comparisons, == is still very common - and you'd use == vs. ===
> depending on what you need.
>
> > […]
>
> Let's agree to disagree.  That's one thing we can always agree on!  :)

I'm talking about the object system. I don't think you're disagreeing
that it's static. Hence coercive scalars are consistent only if you
look at 1/2 the type system. That was the point I was making there.

> > […]
>
> I do too, and I was upfront about their cons, not just pros.  And yet, they
> all bring us to a much better outcome within a relatively short period of
> time (in the lifetime of a language) than the Dual Mode will.

Let's agree to disagree that an ini setting will be better than a
per-file setting.

In fact, I personally think this is major enough of an issue that I
will vote no simply on this reason alone (type behavior depending on
an ini setting in any way shape or form).

> > […]
>
> I'll be happy to get a suggestion from you on how to reword that.
> Ultimately, from the layman user's point of view, she'd be calling foo()
> from one place and have it accept her arguments, and foo() from another
> place and have it reject the very same arguments.

Let me think on it and I will come up with something.

> > […]
>
> First, I'm not aware of smart/safe casts being available or proposed at this
> point.
> Secondly, why at the point the data comes in?  That would be ideal for
> static analyzers, but it's probably a lot more common that it will be done
> at the first point in time where it gets rejected.

By "smart cast" I was referring to a function which checked
 `is_numeric()`. Not a new language construct.

> I have a hard time connecting to the 'power' approach.  I think developers
> want their code to work, with minimal effort, and be secure.  Coercive
> scalar type hints will do an excellent job at that.  Strict type hints will
> be more work, are bound to a lot of trigger "Oh come on" responses, and as a
> special bonus - proliferate the use of explicit casts.  Let me top that -
> you'd have developers who think they're security conscious, because they're
> using strict mode - with code that's full of explicit casts.

I agree we should have users avoid explicit casts. That's why the
dual-mode proposal exists. If users don't want to control their types,
they should use the default mode. And everything works fine.

If they know what they want, then the explicit cast becomes a
documenting piece of information that "this is supposed to happen".
Ex:

function takesInt(int $a) {}

function foo(float $b) {
    return takesInt($b);
}

In weak mode, that "just works". But is it supposed to just work? You
have no idea. The next developer who comes will look at it and ask "is
that supposed to truncate, or was that an oversight?" and have no
idea. But in strict mode, placing an explicit cast before $b shows the
next developer who comes there "the truncation was intentional".

> > […]
>
> It's actually patently true.  We don't believe that is the case.  QED.

To understand why "we don't believe" can be false, let's make an
analogy: I can say that I don't believe in gravity. That doesn't mean
that the opinion isn't patently false just because it was stated as an
opinion (or rather the "believe" is true, but the implication of the
belief is false)...

>
> > […]
>
> I think it's fair to say that while we were unable to convince you there's
> no tangible extra value in Strict STH compared to any other kind of STH that
> guarantees the type of value a function will get, you were also unable to
> convince Dmitry, Stas or myself - all of which independently discussed it
> with you.  Again, despite that, I'm not saying that you're "patently wrong",
> just that I don't believe you're right.

I've built a static analyzer that's public. I've talked to people who
build them for a living. I don't claim to be an expert in them (far
from it), but what I've seen and learned is that what you're talking
about here either isn't possible (yet) or is difficult enough to be
impractical (in terms of computing resources necessary).

You can disagree with me all you want. You don't even need to convince
me. All you need to do is disprove me. Show me a static analyzer for a
sufficiently dynamic language (Scalar PHP or full JS - not ASM.js -
would work) and I'll happy apologize and retract the comment. But so
far all I've seen are people saying it's possible even in presence of
arguments to the contrary (why it's not possible).

Thanks,

Anthony

---

## #83424 — Marcio Almada — 2015-02-21T20:13:48+00:00

URL: https://externals.io/message/83405#83424 · In reply to: #83405

Hi,

2015-02-21 14:22 GMT-03:00 Zeev Suraski <zeev@zend.com>:

> All,
>
> I’ve been working with François and several other people from internals@
> and the PHP community to create a single-mode Scalar Type Hints proposal.
>
> I think it’s the RFC is a bit premature and could benefit from a bit more
> time, but given the time pressure, as well as the fact that a not fully
> compatible subset of that RFC was published and has people already
> discussing it, it made the most sense to publish it sooner rather than
> later.
>
> The RFC is available here:
>
> wiki.php.net/rfc/coercive_sth
>
> Comments welcome!
>
> Zeev
>

Thanks for your effort and for proposing the RFC so quick. But indeed, as
you said, this is really premature.

According to my interpretation the RFC proposes a potentially huge bc break
on internal functions usage while the competing (recently withdraw) RFC was
BC compatible regarding this. Having this proposal without a working patch,
so we can try the real impact it could have before form opinions, frankly,
doesn't sound like a good idea.

I know it's still a draft but, considering the RFC is aimed to v7.0, I hope
to see a working implementation before the feature freeze just like what
was exemplary made with the other previous withdraw proposals.

Thanks,
Márcio

---

## #83425 — Pierre Joye — 2015-02-21T20:17:30+00:00

URL: https://externals.io/message/83405#83425 · In reply to: #83417

> Sorry for the previous prematurely sent email, looks like I found a new
> keyboard shortcut :)
>
> > […]
>
> I don't think it's mis-stating the key concern.  At least not based on what
> I've heard from most people here over the last few months.

I think this argument should be avoided from now on.

We surely can go wild and provide names and numbers, all being better
than other. But at the end of the day, we vote on a proposal. A
proposal  written by one or many persons (name them or leave them)
with a clear specification, patch, impact (backed by tests), etc. Any
other random estimation or popularity contests are pointless and
counter productive.


> > […]
>
> Not in the way Andrea proposed it, IIRC.  She opted to go for consistency
> with internal functions.  Either way, at the risk of being shot for talking
> about spiritual things, Dynamic STH is consistent with the dynamic spirit of
> PHP, even if there are some discrepancies between its rule-set and the
> implicit typing rules that govern expressions.  Note that in this RFC I'm
> actually suggesting a possible way forward that will align *all* aspects of
> PHP, including implicit casting - and have them all governed by a single set
> of rules.

You did not answer my questions about BC. Changing the way we do it is
much more likely to break things than providing a choice to move to
another mode. I am in favor of do not break things by default and give
the option to actually use strict typing when desired (yes, I repeat
myself here).

> > […]
>
> I think you're correct on comparisons, but not so much on the rest.  Dynamic
> use of scalars in expressions is still exceptionally common in PHP code.
> Even with comparisons, == is still very common - and you'd use == vs. ===
> depending on what you need.

I do not think using legacy codes to determine which (optional)
features should be implemented in php is the right way. Really not.

> > […]
>
> Let's agree to disagree.  That's one thing we can always agree on!  :)

I am not sure there is something to agree on but something to actually
validate against existing codes. We can't do it until this RFC has a
patch.

> > […]
>
> I'd have to partially agree with you here;  But if you read the RFC through
> including its future recommendations, you'd see it's perhaps the first
> attempt in 20 years to fix that.  Instead of doing that through the
> introduction of a 3rd (albeit simplistic rule-set that only pays attention
> to zval.type) - a creation of a single set of rules that will be consistent
> across the whole language, beginning with userland and internal functions.

I agree we should fix that. I however disagree that the fix may break
BC. Many proposed that back to 5.0 and we did not agree on changing
that. The situation now is no different.

> > […]
>
> I do too, and I was upfront about their cons, not just pros.  And yet, they
> all bring us to a much better outcome within a relatively short period of
> time (in the lifetime of a language) than the Dual Mode will.



> > […]
>
> I'll be happy to get a suggestion from you on how to reword that.
> Ultimately, from the layman user's point of view, she'd be calling foo()
> from one place and have it accept her arguments, and foo() from another
> place and have it reject the very same arguments.
>
> > […]
>
> Of course we're relying on information coming from outside, as we all know,
> this is one of the most common use cases for PHP.
> While theoretically you're right, in practice, in the vast majority of cases
> it wouldn't play out like that.  The string column won't be tested
> exclusively with "123" inputs.  As soon as there's a non-numeric-string
> input, it'll fail.  That's likely to happen very early in the process, and
> that's before considering that if there's such a huge mismatch between the
> semantic meaning of the column and what the function expects - the problem
> is likely to be found even sooner, since the function will simply not
> perform its intended job.
>
> On the flip-side, imagine that same developer using strict types.  Feeding
> the function that integer in string form gets rejected.  What are her
> options?  The developer is likely  to just explicitly cast the value into an
> int, giving up on any and all sanitization that coercive types would offer
> her, happily accepting "Apples" and "100 Dalmatians" as valid inputs.  That,
> on the other hand, is a *very* likely scenario.

You are underestimating the knowledge and experiences of our users. I
do  not think developers looking for strict types will do what you are
suggesting.

> > […]
>
> First, I'm not aware of smart/safe casts being available or proposed at this
> point.
> Secondly, why at the point the data comes in?  That would be ideal for
> static analyzers, but it's probably a lot more common that it will be done
> at the first point in time where it gets rejected.
>
> > […]
>
> This is bound to be misquoted and used against me, but I don't think it's a
> good idea to give the user the choice in such a way.  I could have sworn
> that you tweeted the quote about perfection being not when there's nothing
> left to add, but nothing left to remove, but perhaps it was someone else.
> Either way, two modes are worse than one, if we can come up with a good
> single unified mode that addresses *most* cases.

I disagree. One mode remains untouch, fully BC ensures a smooth and
fast (or lest slow) migration to 7. The 2nd mode will attract the non
negligible amount of users looking forward to have such mode.

On the other hand, changing the default mode is very likely to be a
real pain during migration. This is not the kind of things that are
easy to catch, cannot be automated (like code conversions and the
likes).

> Remember you can always implement custom type checking to your heart's
> content.  You can easily implement if (!is_int($foo)) { exit; } in the
> not-so-common-cases where accepting "42" as 42 might be disastrous.
> However, on the caller side, forcing people to clutter their code with
> casts - many casts - either explicit casts or custom ones - is going to
> affect a lot more developers in a lot more places.  The bang for the buck of
> adding strict mode is just not there, in my humble opinion of course.

Now you are misleading readers about what it is proposed. A user of a
library will never ever be forced to cast. This is not what the dual
proposal does and it is not what it will do. The strict mode is
confined to the given library files and code, where the library
authors decided to enable it. I would very much appreciate to stop
using this as an argument as it is simply not correct. We do not more
confusions about the respective proposals.


> > […]
>
> I have a hard time connecting to the 'power' approach.  I think developers
> want their code to work, with minimal effort, and be secure.  Coercive
> scalar type hints will do an excellent job at that.  Strict type hints will
> be more work, are bound to a lot of trigger "Oh come on" responses, and as a
> special bonus - proliferate the use of explicit casts.  Let me top that -
> you'd have developers who think they're security conscious, because they're
> using strict mode - with code that's full of explicit casts.

Again, speculations on random numbers or code reviews.

> > […]
>
> We listed all what we believe to be misconceptions that were brought up on
> internals.  As recently as yesterday, you had a PHP power user (Larry) that
> was under the strong impression Strict STH would yield substantial
> performance benefits.

We  agreed that performance is totally irrelevant to this discussions.
And this time my team has provided numbers to back this statement,
after Dmitry's reply worrying (a bit) about the performance impact,
for the 1st time in this discussion). So let move on this aspect,
waste of time :)

> Given that it was claimed in the past, and since we
> can't assume every voter reads every last word that's written on internals@
> threads, it was important to list that here even if it's not mentioned in
> the Strict/Dual mode RFC.

We could add this statement in all related RFCs: "performance is not
impacted by this RFC, in any direction". And move on.

> It's also worth mentioning that there are people who *assume* that strict
> type hints can somehow help performance, without being domain experts at
> neither the engine nor JIT, even if they weren't exposed to the explicit
> statements that suggested that on blogs and on internals@ - adding to the
> importance of making it clear that there are no performance benefits to that
> approach.

Everyone, even "experts", are  pretty much assuming a lot of things
about type hinting. We should focus on the design and concept behind
that, not a potential advantages or other "upcoming" new features but
the actual benefits of each proposal from an implementation, clarity,
taste or applications requirements point of views.

> > […]
>
> It's actually patently true.  We don't believe that is the case.  QED.

Both are true and false, let call it the Schroedinger Question of the
day. Refer to my previous line for this question as well. This is not
in the scope of these RFCs.

> While at it, can we stop using that 'patently false', and stick for
> constructive wording such as 'I disagree'?

I see nothing wrong with "patently". I see much more wrong to totally
ignore feedback, ideas, replies etc. while playing the politically
correct writer. But I am being OT again.

Cheers,
-- 
Pierre

@pierrejoye | http://www.libgd.org

---

## #83428 — Zeev Suraski — 2015-02-21T21:02:37+00:00

URL: https://externals.io/message/83405#83428 · In reply to: #83420

> -----Original Message-----
> From: Pádraic Brady [mailto:padraic.brady@gmail.com]
> Sent: Saturday, February 21, 2015 9:56 PM
> To: Zeev Suraski
> Cc: Anthony Ferrara; PHP internals
> Subject: Re: [PHP-DEV] Coercive Scalar Type Hints RFC
>
>
> The sentence stresses garbage in too much to read as accurate. To clarify,
> there is a) garbage in due to weak coercion and b) a function being called
> with a string when the typehint says int. Both are separate concerns
> around
> error detection. Stricter coercion can enable only one of these two, for
> example. That's better than neither, of course! The coercion rules were
> stricter than I expected based on previous emails. Stressing one too much
> might suggest to a reader that the second concern does not exist.

As I told Anthony, based on what I saw on the list, the former appeared to
be a much more widely-held concern than the latter.

> Other pedantic comment: "numerous" is probably too strong a word there.
> The advantages may vary by person, but usually fit within basic
> five-finger
> math. It would be more important to enumerate them rather than selecting
> one as primary.

Thanks, changed to 'several'.  Double thanks, as I always thought 'Numerous'
was more or less equivalent to 'Several', and you made me look it up :)


> On the RFC rules themselves, a few comments:
>
> 1. Happy to see leading/trailing spaces excluded.

Happy to see you happy!

> 2. Rules don't make mention of leading zeroes, e.g. 0003 3. "1E07" might
> be
> construed as overly generous assuming we are excluding stringy integers
> like
> hex, oct and binary 4. I'm assuming the stringy ints are rejected?

It's up for discussion.  I personally don't have very strong feelings on how
we deal with these cases, as the main thing I care about is for the common
cases to work.  That said, if it was entirely up to me, I'd accept "0003"
but not  "1E07" - as the latter is considered floating point:
$x = "1e7";
print gettype($x+0);  // would print double

But if rejecting leading zeros is what's needed to get a lot more people to
support it, I can live with that.

> 5. Is ".32" coerced to float or only "0.32"? Merely for clarification.

With the same disclaimer as the one for the previous answer, I'd go with
accepting ".32" in the same way `is_numeric()` accepts it.

> 7. In string to float, only capital E or also small e?

I think both, same `is_numeric()` rationale - same disclaimer.

> 8. I'll never stop call them "stringy" ints.

I can live with that :)

Thanks for the feedback!

Zeev

---

## #83429 — Markus Fischer — 2015-02-21T21:18:03+00:00

URL: https://externals.io/message/83405#83429 · In reply to: #83405

Hi Zeev,


> I’ve been working with François and several other people from internals@
> and the PHP community to create a single-mode Scalar Type Hints proposal.
> 
> I think it’s the RFC is a bit premature and could benefit from a bit more
> time, but given the time pressure, as well as the fact that a not fully
> compatible subset of that RFC was published and has people already
> discussing it, it made the most sense to publish it sooner rather than
> later.
> 
> http://wiki.php.net/rfc/coercive_sth

Thanks for the refreshed approach. Although there are already oh-so-many
RFCs and discussion, I found the sum up to be very clear. Thanks to you
at al.


1) About impact / BC

There's one thing I never understood, even not for 0.3 which almost went
through: why have this impact on internal
function/zend_parse_parameters/ZPP at all?

Why not just keep this strictly user-land /for now/ ?

The user-land change is much more controllable. The internal function
change is ... not sure how to say. Has such a big impact and I'm not
sure what should be the gain at all here.


2) I'm with Pierre regarding accepting e.g. 42.0 for an int. Just
imagine you pass the result of a calculation which happens to be a
result with a clean .0 fractional part and everything works. The next
time you calculate with a different input and *boom* your value is 42.1
and thus reject. That's quite a POLA [1] right there.



I know I will derail this whole thing when I write the next point but I
really think one of the best ways to move forward is to
- only support strict types, e.g. function foo(string $bar)
- in user-land code

That way the there's almost no BC impact sans the possible clashes of
classnames (which I probably just missed how this will be resolved?).


Future RFCs could still reason about other typo of hints (initial weak
STH or now this coercive STH) and expand on the syntax.



thanks,
- Markus

[1] http://en.wikipedia.org/wiki/Principle_of_least_astonishment

---

## #83434 — Benjamin Eberlei — 2015-02-21T21:38:33+00:00

URL: https://externals.io/message/83405#83434 · In reply to: #83405

Hi Zeev,



> All,
>
>
>
> I’ve been working with François and several other people from internals@
> and the PHP community to create a single-mode Scalar Type Hints proposal.
>
>
>
> I think it’s the RFC is a bit premature and could benefit from a bit more
> time, but given the time pressure, as well as the fact that a not fully
> compatible subset of that RFC was published and has people already
> discussing it, it made the most sense to publish it sooner rather than
> later.
>
>
>
> The RFC is available here:
>
>
>
> wiki.php.net/rfc/coercive_sth
>
>
>
> Comments welcome!
>

I was really looking forward to the RFC. However the dependence on an INI
setting and the question of massive internal BC break are a bit too much I
think.

They are necessary as you explain to allow internal functions/ZPP to have
the same conversion rules as userland functions. This INI setting is quite
similar to introducing two modes as well, but on the server configuration
level instead in a much more fine granular way in scalar type hints v0.5.

I see much more compatibility problems for third party libraries here.

Now if I had to decide between having two modes on a granular file level or
an INI setting (option 2/3) or massive BC breaks (option 1) to get scalar
type hints in PHP, then two modes with declare() doens't look, because I
can pick the mode I want, and no-one can force it on me.


>
> Zeev

---

## #83436 — Zeev Suraski — 2015-02-21T22:02:04+00:00

URL: https://externals.io/message/83405#83436 · In reply to: #83422

> -----Original Message-----
> From: Anthony Ferrara [mailto:ircmaxell@gmail.com]
> Sent: Saturday, February 21, 2015 10:08 PM
> To: Zeev Suraski
> Cc: PHP internals
> Subject: Re: [PHP-DEV] Coercive Scalar Type Hints RFC
>
> Zeev,
>
> I won't nit-pick every point, but there are a few I think need to be
> clarified.
>
> > […]
>
> The point I was making up to there is that we currently have 2 type
> systems: user-land object and ZPP-scalar. So in any given function you
> have 2
> type systems interacting. The current ZPP scalar type is dynamic, and
> user-
> land object static.

Objects and scalars are fundamentally different, definitely in PHP..
There's no standard way to convert an instance of a certain class to an
instance of another class, at least not in PHP.  There is, however, a
standard way of converting different types of scalars to one another, and
this behavior is extremely ubiquitous in PHP.  That is the reason that when
class type hints were introduced, it was at the *condition* that we'll not
have strict scalar type hints, because scalars were (and still are) so
fundamentally different than objects and in many cases can losslessly change
type in a well-defined manner.  Perhaps if we had the coercive STH idea back
then we could have saved us all a lost decade without scalar type hints.

I'll say it again - scalars and objects (and for that matter any non-scalar
type including arrays and resources) - are inherently different, and
striving for consistency between them should not be a goal IMHO.

> Let's agree to disagree that an ini setting will be better than a per-file
> setting.

We can agree to disagree on that, but not on the fact that the Coercive STH
RFC provides a roadmap, at the end of which we'd have a single mode,
consistently behaving(*) and more secure-for-everyone language - and one
without that INI entry (it's a temporary measure that will be removed).  The
Dual Mode RFC, on the other hand, we're introducing two modes that we'll
have to support for all eternity, with two potential 'camps' of developers
forming up, and with no security benefits for anybody who doesn't choose to
flip on the strict switch.

(*) With the exception of Scalar/non-Scalar consistency, which again, I find
hard to accept as a valid goal.

> > […]
>
> Let me think on it and I will come up with something.

Thanks.

> I agree we should have users avoid explicit casts. That's why the
> dual-mode
> proposal exists. If users don't want to control their types, they should
> use the
> default mode. And everything works fine.

This ignores the reasonable guesstimate - raised by several people here -
that many will flip Strict mode on because they'd think it makes them
inherently safer, faster, or just a good thing to do.  Everything I've
learned about PHP in the last couple of decades tells me there are going to
be plenty of those.  Those are the same people who would quickly then add
explicit casts to make the code work again;  Those are also people who would
benefit a lot more from a single mode system that would point out real
problems in their code, with likely very few false positives or false
negatives.

> > […]
>
> To understand why "we don't believe" can be false, let's make an
> analogy: I can say that I don't believe in gravity. That doesn't mean that
> the
> opinion isn't patently false just because it was stated as an opinion (or
> rather
> the "believe" is true, but the implication of the belief is false)...

Of course an opinion can be patently false, however, you were talking about
what I wrote, not the opinion.
Let me illustrate it.  Watch youtu.be/kjvQ9eT_t-U - it's worth the one
minute of your time if you haven't already seen it.  Now, apparently, that
guy absolutely believes in what he says.  What he says is absolute nonsense,
but not the fact he believes in it.
Now, I took an extreme case to illustrate my point and I obviously don't aim
to be compared with this guy, but hopefully that takes the nitpicking point
across.  Sorry, I've become a bit sensitive to the explosion of 'patently
false' statements here, I find them somewhat offensive and aiming to shut
discussion down.

To the point itself, with all due respect, the Static Analysis gains you
believe exist in Strict STH aren't even remotely at the same bucket as
gravity, which has been proven with scientific method.  More on that below.


> > […]
>
> I've built a static analyzer that's public. I've talked to people who
> build them
> for a living. I don't claim to be an expert in them (far from it), but
> what I've
> seen and learned is that what you're talking about here either isn't
> possible
> (yet) or is difficult enough to be impractical (in terms of computing
> resources
> necessary).
>
> You can disagree with me all you want. You don't even need to convince me.
> All you need to do is disprove me.

Actually, that's not the scientific method I know.  In the scientific method
I know, a theory needs to be proven for it to be accepted as true - and not
as you seem to suggest, that a theory is deemed true unless it's proven
untrue.

 Show me a static analyzer for a sufficiently
> dynamic language (Scalar PHP or full JS - not ASM.js - would work) and
> I'll
> happy apologize and retract the comment.

First, you don't need to retract the comment as evidently it's clear you
believe in it.  It's fine that we hold different views.  But we should both
be allowed to say what we think and have this difference of opinion be
widely known.
Secondly, there you are:  http://www.checkmarx.com/ - they've been
developing pretty amazing static analyzers for PHP for years, and without
any type of scalar hints - strict or weak.
Last - I'm not sure how whether or not static analyzers exist for PHP proves
or disproves whether the delta between Strict/Dynamic type hints helps
Static Analysis in any way.  You could still be right even though static
analyzers already exist for PHP (they could be made better, perhaps), and
you could still be wrong if there were no static analyzers for PHP in
existence.

> But so far all I've seen are people
> saying it's possible even in presence of arguments to the contrary (why
> it's
> not possible).

My recommendation is that we again agree to disagree, as you suggested.
Agreeing to disagree doesn't mean I accept your position as I accept
gravity, or that I start hiding the fact I disagree (and vice versa).  It
means we both disagree with each other respectfully.  In the RFC I
intentionally didn't say that Static Analysis being helped by Strict STH is
nonsense or 'patently false' - but instead, pointed out that we don't
believe there are substantial gains to be had there.

Thanks,

Zeev

---

## #83437 — Zeev Suraski — 2015-02-21T22:12:11+00:00

URL: https://externals.io/message/83405#83437 · In reply to: #83424

Márcio,



I hope to be able to work on an actual implementation and have something by
the end of the upcoming week, allowing us all to experiment.

Other than tweaking the conversion table, which based on the feedbacks I *
*believe** can be done in a way everyone can live with – I agree that the
biggest open question is how we deal with internal functions.



Also note that the, the 2nd proposed option in the RFC (“Emit `E_DEPRECATED` 
in 7.0, move to `E_RECOVERABLE_ERROR` in v7.1 or v8.0”) – of marking
newly-rejected-conversions as `E_DEPRECATED` is not considered as a BC break
IMHO.  The code would still work, and the likelihood that something bad was
legitimately found is pretty high.



Given the compressed timeline, I wanted to gauge the general response as
soon as possible, and also start the RFC discussion process as soon as
possible, which meant we couldn’t include the implementation to go along
with it.



Two more things regarding the competing RFC – it’s still alive, and being
promoted for PHP 7.0;  And while it doesn’t create a huge BC break, it
allows developers to selectively create localized BC breaks, on a per file
basis.



Thanks for the feedback!


Zeev



Thanks for your effort and for proposing the RFC so quick. But indeed, as
you said, this is really premature.

According to my interpretation the RFC proposes a potentially huge bc break
on internal functions usage while the competing (recently withdraw) RFC was
BC compatible regarding this. Having this proposal without a working patch,
so we can try the real impact it could have before form opinions, frankly,
doesn't sound like a good idea.

I know it's still a draft but, considering the RFC is aimed to v7.0, I hope
to see a working implementation before the feature freeze just like what
was exemplary made with the other previous withdraw proposals.

Thanks,

Márcio

---

## #83439 — francois@php.net — 2015-02-21T22:17:51+00:00

URL: https://externals.io/message/83405#83439 · In reply to: #83425

Hi Pierre,

I'm currently writing a patch to test the proposed ruleset, as BC is the key point.

If BC breaks are so massive that we have to revert to the original 'weak' mode, I will be the first one to vote for dual-mode.

There will be two slightly different branches : one totally disabling (IS_LONG|IS_FLOAT|IS_STRING to bool) and one implementing the current way of converting these (with the small modification about numeric strings recognized as false). There may be a first level without support for trailing blanks but it is not important as it is an extension of the current behavior, not a restriction.

More when something is ready.

Regards

François

---

## #83440 — Anthony Ferrara — 2015-02-21T22:25:12+00:00

URL: https://externals.io/message/83405#83440 · In reply to: #83436

Zeev,


> > […]
>
> Objects and scalars are fundamentally different, definitely in PHP..
> There's no standard way to convert an instance of a certain class to an
> instance of another class, at least not in PHP.  There is, however, a
> standard way of converting different types of scalars to one another, and
> this behavior is extremely ubiquitous in PHP.  That is the reason that when
> class type hints were introduced, it was at the *condition* that we'll not
> have strict scalar type hints, because scalars were (and still are) so
> fundamentally different than objects and in many cases can losslessly change
> type in a well-defined manner.  Perhaps if we had the coercive STH idea back
> then we could have saved us all a lost decade without scalar type hints.
>
> I'll say it again - scalars and objects (and for that matter any non-scalar
> type including arrays and resources) - are inherently different, and
> striving for consistency between them should not be a goal IMHO.

They are inherently different because we (PHP) say they are. Plenty of
other languages out there say they are not inherently different.

You want to keep them separate? That's fine. But it can be useful to
model a language without making them separate. So I don't agree that
they are "fundamentally" different.

Is it worth going into that now? No. But I think it's a valid viewpoint.

> > […]
>
> We can agree to disagree on that, but not on the fact that the Coercive STH
> RFC provides a roadmap, at the end of which we'd have a single mode,
> consistently behaving(*) and more secure-for-everyone language - and one
> without that INI entry (it's a temporary measure that will be removed).  The
> Dual Mode RFC, on the other hand, we're introducing two modes that we'll
> have to support for all eternity, with two potential 'camps' of developers
> forming up, and with no security benefits for anybody who doesn't choose to
> flip on the strict switch.

The other RFC comes from the standpoint that there's nothing wrong
with coercive. So there's no need for a roadmap. There's no need for
people's code to break when they upgrade, ever. There's no need for an
upgrade path because everything will just work. It introduces a new
mode that users can opt into. And in practice, they should use both
modes because different needs have different solutions.

"with two potential 'camps' of developers forming up"

Have you looked at the community lately? That's been happening for a
decade. One camp likes to engineering everything out using classes and
libraries. The other keeps using PHP procedurally and ignoring
changing "best practices" (and I do mean the quotes). Does that make
one better than the other? NO.

And that's PHP's strength. It gives both sides the power to keep doing
what they want to be doing without having to give up or be burdened by
the other side.

And that's what my RFC provides. It doesn't force behavior or belief
on anyone, it gives the choice.

> > […]
>
> This ignores the reasonable guesstimate - raised by several people here -
> that many will flip Strict mode on because they'd think it makes them
> inherently safer, faster, or just a good thing to do.  Everything I've
> learned about PHP in the last couple of decades tells me there are going to
> be plenty of those.  Those are the same people who would quickly then add
> explicit casts to make the code work again;  Those are also people who would
> benefit a lot more from a single mode system that would point out real
> problems in their code, with likely very few false positives or false
> negatives.

Sure, some people will do that. Just like people still use single
quotes because they are faster.

But the way you fix that is not to handicap the language (we do have
eval() and goto, no?) but to educate the users.


> First, you don't need to retract the comment as evidently it's clear you
> believe in it.  It's fine that we hold different views.  But we should both
> be allowed to say what we think and have this difference of opinion be
> widely known.
> Secondly, there you are:  http://www.checkmarx.com/ - they've been
> developing pretty amazing static analyzers for PHP for years, and without
> any type of scalar hints - strict or weak.

Vulnerability scanning is a subset of static analysis. One that does
not rely on typing, but tainting. All it needs to do is watch variable
flow with explicit "markers" to make the input safe. There are
definitely other techniques involved as well.

What I'm talking about is correctness provers. Static analyzers that
look at an entire codebase and ensures that information flow through
it is correct and will not error at runtime. Precisely what HHVM's
type checker does.

> Two more things regarding the competing RFC – it’s still alive, and being
> promoted for PHP 7.0;  And while it doesn’t create a huge BC break, it
> allows developers to selectively create localized BC breaks, on a per file
> basis.

No, it does not. A BC break is something where existing code works,
and you do nothing more than upgrade and have the new code not work
anymore.

With the other dual-mode RFC, if a user opts-in (enables strict mode),
if code doesn't work that's not a BC break. That's a case of "you told
us explicit you don't want this code to work if it's invalid, and
guess what, it's invalid".

Anthony

---

## #83441 — Zeev Suraski — 2015-02-21T22:25:55+00:00

URL: https://externals.io/message/83405#83441 · In reply to: #83434

Benjamin,



There’s a fundamental difference between the two RFCs that goes beyond
whether using a global INI setting and the other per-file setting.  The
fundamental difference is that the endgame of the Dual Mode RFC is having
two modes – and whatever syntax we’ll add, will be with us forever;  and in
the Coercive STH RFC – the endgame is a single mode with no INI entries,
and opening the door to changing the rest of PHP to be consistent with the
same rule-set as well (implicit casts).   The challenge with the Coercive
STH RFC is figuring out the best transition strategy, but the endgame is
superior IMHO.



Regarding the proposed migration options, yes, if we pick option #2 or #3 –
we’d be introducing an INI entry governing runtime behavior is something
nobody here wants, myself included – but given that it’ll be time limited
(perhaps for as short as 1 or 2 years) – perhaps that’s something we can
live with.



Additional options we could entertain are:

4. Not applying the rules for internal functions at all.  Personally I’m
not very fond of this option.

5. Go for just `E_DEPRECATED` in 7.0.  Change `E_DEPRECATED` to
 `E_RECOVERABLE_ERROR` in 7.1/7.2/8.0 (TBD).

6. Same as #5, but also provide a mechanism similar to declare() as the
temporary measure for strict campers to explicitly ask for
E_RECOVERABLE_ERROR’s to be triggered.  They will no longer be necessary
when we change `E_DEPRECATED` to `E_RECOVERABLE_ERROR` in 7.1/7.2/8.0.



Thoughts?



Zeev



I was really looking forward to the RFC. However the dependence on an INI
setting and the question of massive internal BC break are a bit too much I
think.



They are necessary as you explain to allow internal functions/ZPP to have
the same conversion rules as userland functions. This INI setting is quite
similar to introducing two modes as well, but on the server configuration
level instead in a much more fine granular way in scalar type hints v0.5.



I see much more compatibility problems for third party libraries here.



Now if I had to decide between having two modes on a granular file level or
an INI setting (option 2/3) or massive BC breaks (option 1) to get scalar
type hints in PHP, then two modes with declare() doens't look, because I
can pick the mode I want, and no-one can force it on me.





Zeev

---

## #83442 — pajousek@gmail.com — 2015-02-21T22:39:44+00:00

URL: https://externals.io/message/83405#83442 · In reply to: #83441

> There’s a fundamental difference between the two RFCs that goes beyond
> whether using a global INI setting and the other per-file setting.  The
> fundamental difference is that the endgame of the Dual Mode RFC is having
> two modes – and whatever syntax we’ll add, will be with us forever;  and in
> the Coercive STH RFC – the endgame is a single mode with no INI entries,
> and opening the door to changing the rest of PHP to be consistent with the
> same rule-set as well (implicit casts).   The challenge with the Coercive
> STH RFC is figuring out the best transition strategy, but the endgame is
> superior IMHO.

Hello,

the two modes was something that I didn't like, at all, as a userland
developer. It seems really scary that decision to add 2 modes would
mean that every PHP code could have been written in any of these 2
ways and it would stick forever with PHP, because removing it again if
it proved to be a bad feature would be IMHO really painful.

So a single mode is infinitely better than 2 modes.

Also, personally, I would prefer #1 or #2 version for internal
functions, but definitely without an INI switch. Not being able to
change it on some hostings could make development for the transition
period kinda painful.

Regards
Pavel Kouril

---

## #83443 — Zeev Suraski — 2015-02-21T22:47:57+00:00

URL: https://externals.io/message/83405#83443 · In reply to: #83440

> -----Original Message-----
> From: Anthony Ferrara [mailto:ircmaxell@gmail.com]
> Sent: Sunday, February 22, 2015 12:25 AM
> To: Zeev Suraski
> Cc: PHP internals
> Subject: Re: [PHP-DEV] Coercive Scalar Type Hints RFC
>
> Zeev,
>
>
> "with two potential 'camps' of developers forming up"
>
> Have you looked at the community lately? That's been happening for a
> decade. One camp likes to engineering everything out using classes and
> libraries. The other keeps using PHP procedurally and ignoring changing
> "best
> practices" (and I do mean the quotes). Does that make one better than the
> other? NO.

I don't think these two camps map to the strict and dynamic camps,
definitely not for the userbase at large.
Which means that whatever camps we have today, we'd have more - one extra
point of division.

> And that's PHP's strength. It gives both sides the power to keep doing
> what
> they want to be doing without having to give up or be burdened by the
> other
> side.

I explained both in the RFC and here why I don't think providing two modes
for doing something quite similar are good.  We can agree to disagree :)

> Sure, some people will do that. Just like people still use single quotes
> because
> they are faster.

Not quite IMHO - that example actually requires some relatively advanced
knowledge.  Strict, with the amount of noise that Scalar Type Hints are
bound to get (and are already getting) - is bound to have a lot more
exposure than single quotes being faster ever had.  And it's therefore very
likely it'll be used by people who shouldn't really be using it.

Let's leave the Static Analysis part aside, and agree to disagree as we
already did numerous times but failed to implement.

> > […]
>
> No, it does not. A BC break is something where existing code works, and
> you
> do nothing more than upgrade and have the new code not work anymore.
>
> With the other dual-mode RFC, if a user opts-in (enables strict mode), if
> code
> doesn't work that's not a BC break. That's a case of "you told us explicit
> you
> don't want this code to work if it's invalid, and guess what, it's
> invalid".

That's splitting hairs IMHO.  The bottom line is that many people will
undergo the same process Rasmus did as he experimented, flipping the switch
on because it's a best practice, and start having to fix their code to work.
But we can also agree on what we always agree here too :)

Thanks,

Zeev

---

## #83445 — Lester Caine — 2015-02-21T23:13:39+00:00

URL: https://externals.io/message/83405#83445 · In reply to: #83420

> 1. Happy to see leading/trailing spaces excluded.
Fixed length fields may well be a data source so having to strip them
before using them just seems a backward step. The basic C library simply
strips the white space so are we looking at using an alternative?

> 2. Rules don't make mention of leading zeroes, e.g. 0003
Again data may well be zero padded. This is more likely to be historic
material, but it's yet another extra processing step. If we have to
process data before then asking if it's a valid number what is the
advantage of this? However of cause the C library switches to octal mode
and needs pre processing of leading zero's anyway.

> 3. "1E07" might be construed as overly generous assuming we are
> excluding stringy integers like hex, oct and binary
Yet again ... If we have to add a lot of extra checks then why can't we
simply ask if the data is a usable integer. At the end of the day it
does depend on where the data was sourced? Binary data is only usable if
we know that it is binary, or we will be converting some other format
anyway?

> 4. I'm assuming the stringy ints are rejected?
Source material may be 'stringy ints', so all that does is say "we can't
use the original variable it has to be converted" rather than we can and
use it's 'non-stringy' view.

> 5. Is ".32" coerced to float or only "0.32"? Merely for clarification.
Omitting the leading zero is normal when doing hand keyed data entry.
.32 is a valid data entry ... Omitting perhaps 20% of characters speeds
data entry.

> 6. Boolean coercion from other types... Not entirely sure myself.
> Completely off the cuff: <=0: false, >0:true, floats and strings need
> not apply.
That would be a major BC break!

> 7. In string to float, only capital E or also small e?
lower case e is common ...

> 8. I'll never stop call them "stringy" ints.
For some funny reason we tend to prefer to view numbers on the screen as
strings ... having the original string with a value which can be used
for calculation is simply how I thought PHP worked. A variable is more
than just a 'value', we need it's name which is a string, and a viewable
string could be useful, along with other flags. I had assumed up until
now that PHP was using that model but it seems not :(

-- 
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

---

## #83446 — Andrey Andreev — 2015-02-21T23:20:25+00:00

URL: https://externals.io/message/83405#83446 · In reply to: #83436

Hi,

I intended on replying to this thread at a later stage (and probably
will), but I just can't ignore this one:


>
> Secondly, there you are:  http://www.checkmarx.com/ - they've been
> developing pretty amazing static analyzers for PHP for years, and without
> any type of scalar hints - strict or weak.
>

Having used that product, I can tell you that it's not at all that
amazing for PHP (maybe it works well for other languages, don't know),
and that's an understatement. In fact, a lot of what it does is to
force you into explicit casts.

Cheers,
Andrey.

---

## #83448 — Pierre Joye — 2015-02-21T23:31:00+00:00

URL: https://externals.io/message/83405#83448 · In reply to: #83436

> > […]
>
> This ignores the reasonable guesstimate - raised by several people here -
> that many will flip Strict mode on because they'd think it makes them
> inherently safer, faster, or just a good thing to do.  Everything I've
> learned about PHP in the last couple of decades tells me there are going
to
> be plenty of those.  Those are the same people who would quickly then add
> explicit casts to make the code work again;  Those are also people who
would
> benefit a lot more from a single mode system that would point out real
> problems in their code, with likely very few false positives or false
> negatives.

This is not even a remotely comparable to a guess.

The users I talk to likes it because they see it as a way to improve their
code, not the performance or security but see it as as cleaner, more
readable, less error prone, more predictable.

Like the drupal case, I would not suggest them to move to strict
everywhere, but modules would be free to do so, or part of the core. And
that without any impact on the 3rd party users. I repeat, without any
impact.

---

## #83449 — Anthony Ferrara — 2015-02-21T23:38:38+00:00

URL: https://externals.io/message/83405#83449 · In reply to: #83443

Zeev,

> > […]
if
> > […]
explicit
> > […]
>
> That's splitting hairs IMHO.  The bottom line is that many people will
> undergo the same process Rasmus did as he experimented, flipping the
switch
> on because it's a best practice, and start having to fix their code to
work.
> But we can also agree on what we always agree here too :)

Saying that turning on an optional and previously unavailable option inside
code causing code breaks is any way a " BC" break is pure FUD.

It is not BC by any definition that we have ever used on on this list, nor
is it BC based on semver nor any other community accepted definition.

Let's please avoid FUD and continue to discuss the proposals at hand...

Anthony

---

Next page: https://externals.io/message/83405.md?page=2
