# [RFC] Coercive Scalar Type Hints

- Thread: https://externals.io/message/83408
- Original archive: https://news-web.php.net/php.internals/83408
- Started by Zeev Suraski on 2015-02-21T17:51:41+00:00
- Messages: 4
- RFC: Coercive Scalar Type Hints (Declined) — https://externals.io/rfc/coercive_sth.md
- 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

---

## #83408 — Zeev Suraski — 2015-02-21T17:51:41+00:00

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

[Resending with the correct Subject line :)]

---

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

---

## #83410 — Pierre Joye — 2015-02-21T17:54:55+00:00

URL: https://externals.io/message/83408#83410 · In reply to: #83408

> [Resending with the correct Subject line :)]
>
> ---
>
> 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!

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

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

---

## #83423 — padraic.brady@gmail.com — 2015-02-21T20:10:05+00:00

URL: https://externals.io/message/83408#83423 · In reply to: #83410

Copying from old thread...please ignore the original.


> > […]
>
> 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

---

## #83461 — Ole Markus With — 2015-02-22T08:54:36+00:00

URL: https://externals.io/message/83408#83461 · In reply to: #83423

>
> 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.
> 

In my mind, certainly a better proposition than those introducing dual
mode. Agree with the comments above, except that I am entirely sure that
boolean coercion from other types should not be allowed.

Cheers,
Ole Markus
