# [RFC-Discuss] Scalar Type Declarations v0.5

- Thread: https://externals.io/message/83117
- Original archive: https://news-web.php.net/php.internals/83117
- Started by Anthony Ferrara on 2015-02-18T20:44:50+00:00
- Messages: 59
- RFC: Scalar Type Hints v0.5 (Implemented (PHP 7.0)) — https://externals.io/rfc/scalar_type_hints_v5.md
- Page 1 of 3: messages 1 to 25 (25 per page, add `?page=N` to the URL)
- Next page: https://externals.io/message/83117.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

---

## #83117 — Anthony Ferrara — 2015-02-18T20:44:50+00:00

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

Dear Internals,

Since the resignation of Andrea, the mixed-mode type hint (called
declaration in the proposal) proposal has been left abandoned.
Considering that the ending votes were 67/34 (66.3%) with several
no-votes being only due to reasonably minor issues with the proposal,
I would like to re-propose her RFC with three minor modifications:

1. declare(strict_types=1) (if used) is required to be the first
instruction in the file only. No other usages allowed.
2. declare(strict_types=1) {} (block mode) is specifically disallowed.
3. int typed variables can resolve a parameter type of float So
calling requiresAFloat(10) will work even in strict mode.

As this topic has and is being discussed to death, I have put a very
large "discussion points" section:
https://wiki.php.net/rfc/scalar_type_hints_v5#discussion_points

I would kindly ask, before replying that you check to see if your
question is answered in that list.

If it is not, please follow up here and I will update the RFC.

If your question is listed and you feel that it wasn't given proper
due, please let's discuss that.

https://wiki.php.net/rfc/scalar_type_hints_v5

Considering this proposal is a minor tweak on an already-discussed and
voted-on proposal, I plan on bringing this RFC to vote 1 week from
today (on February 25th, 2015).

Thanks,

Anthony

---

## #83123 — Leigh — 2015-02-18T21:23:58+00:00

URL: https://externals.io/message/83117#83123 · In reply to: #83117

> Dear Internals,
>
> Since the resignation of Andrea, the mixed-mode type hint (called
> declaration in the proposal) proposal has been left abandoned.
> Considering that the ending votes were 67/34 (66.3%) with several
> no-votes being only due to reasonably minor issues with the proposal,
> I would like to re-propose her RFC with three minor modifications:
>
> 1. declare(strict_types=1) (if used) is required to be the first
> instruction in the file only. No other usages allowed.
> 2. declare(strict_types=1) {} (block mode) is specifically disallowed.
> 3. int typed variables can resolve a parameter type of float So
> calling requiresAFloat(10) will work even in strict mode.
>
> As this topic has and is being discussed to death, I have put a very
> large "discussion points" section:
> https://wiki.php.net/rfc/scalar_type_hints_v5#discussion_points
>
> I would kindly ask, before replying that you check to see if your
> question is answered in that list.

General comments from me, as a radical strictist. No need to reply and
tell me I'm "wrong", these are my opinions.

> Internal Functions Like `ceil()` Return Unexpected Types

My opinion is that functions should return sane types for their
intended purpose, and functions that do not should be "fixed".

> Integers Should Be Accepted For Strict float Arguments
> Int->Float Exception Makes Strict Mode "Flawed"

My opinion is that strict should mean strict.

> Static Analysis Is Possible With Weak Declarations

The advocacy of allowing `accepts_float(returns_int());` doesn't help
the cause of static analysers in strict mode.

> Why Not Add Support For Null?

I agree a null type is pointless, however I would like to raise the
discussion point of existing hinted optional parameters being allowed
a default of null. i.e. fn(Obj $o = null) {}

Do you think this is acceptable for any other types? I can only think
of it being useful if resource and a generic object type are added.
but others may disagree. (Ideally the resource type will go away over
time and will be replaced with objects like GMP anyway :))

Still no mention of a way to enable strict by default. So lets try
some different rationale. If I personally want to develop in strict
mode, I can do that with this proposal, I can add a declare to the top
of every file and be as strict as I like. However not everyone else is
going to want to use my code in strict mode, so they will have to go
and remove some/all of those strict declarations. (Lets take callbacks
being evaluated in the context they are called rather than the one
they are created in). I would like a way of enabling strict by
default, immutable to scripts so that users cannot be forced into this
mode, and lets the radicals and the weaklings* play together in
harmony.

For the rest of the RFC, I either agree with or have no strong
opinions about the points raised.


*it's a joke you guys.

---

## #83124 — Andrey Andreev — 2015-02-18T21:39:01+00:00

URL: https://externals.io/message/83117#83124 · In reply to: #83123

Hi,


> I would like a way of enabling strict by
> default, immutable to scripts so that users cannot be forced into this
> mode, and lets the radicals and the weaklings* play together in
> harmony.
>
> For the rest of the RFC, I either agree with or have no strong
> opinions about the points raised.
>
>
> *it's a joke you guys.
>

I am still bipolar and I still want both to co-exist with no switches
and modes. :)

No joke.

Cheers,
Andrey.

---

## #83125 — Anthony Ferrara — 2015-02-18T21:50:26+00:00

URL: https://externals.io/message/83117#83125 · In reply to: #83123

Leigh,

> > […]
>
> My opinion is that functions should return sane types for their
> intended purpose, and functions that do not should be "fixed".

I agree 100%. I just think that's outside the scope of this proposal.

> > […]
>
> The advocacy of allowing `accepts_float(returns_int());` doesn't help
> the cause of static analysers in strict mode.

Java does exactly this and is statically analyzable. So...?

> Still no mention of a way to enable strict by default. So lets try
> some different rationale. If I personally want to develop in strict
> mode, I can do that with this proposal, I can add a declare to the top
> of every file and be as strict as I like. However not everyone else is
> going to want to use my code in strict mode, so they will have to go
> and remove some/all of those strict declarations. (Lets take callbacks
> being evaluated in the context they are called rather than the one
> they are created in). I would like a way of enabling strict by
> default, immutable to scripts so that users cannot be forced into this
> mode, and lets the radicals and the weaklings* play together in
> harmony.

I missed that discussion point, so I've just added it:
https://wiki.php.net/rfc/scalar_type_hints_v5#why_not_add_an_ini_setting_for_default_mode

> For the rest of the RFC, I either agree with or have no strong
> opinions about the points raised.

Thanks for the input :-)

Anthony

---

## #83126 — Leigh — 2015-02-18T21:57:55+00:00

URL: https://externals.io/message/83117#83126 · In reply to: #83125

> > […]
>
> Java does exactly this and is statically analyzable. So...?

As discussed elsewhere. You're absolutely right, it is up to the
analyser to throw a warning on this because it is a type-based
conversion rather than value based one.

---

## #83129 — Albert Casademont Filella — 2015-02-18T22:21:11+00:00

URL: https://externals.io/message/83117#83129 · In reply to: #83117

Hi Anthony!

Thanks for bringing this up again. I am asking you the same I asked Andrea
2 weeks ago on Twitter: make it a triple option vote please. She didn't
want to do it, hope you do! This way you eliminate the neverending
discussion about weak vs strict, let the votes decide and see who really
prefers weak type hinting only and who prefers the stricter way, both camps
will have an option to vote.

So I propose 3 voting options: Yes (strict), Yes (weak), No. The Yes votes
combined need 2/3 of the votes. Then a simple majority of 50%+1 between the
different Yes votes is needed.

Thanks!

Albert

On Wed, Feb 18, 2015 at 9:44 PM, Anthony Ferrara <ircmaxell@gmail.com>
wrote:

> Dear Internals,
>
> Since the resignation of Andrea, the mixed-mode type hint (called
> declaration in the proposal) proposal has been left abandoned.
> Considering that the ending votes were 67/34 (66.3%) with several
> no-votes being only due to reasonably minor issues with the proposal,
> I would like to re-propose her RFC with three minor modifications:
>
> 1. declare(strict_types=1) (if used) is required to be the first
> instruction in the file only. No other usages allowed.
> 2. declare(strict_types=1) {} (block mode) is specifically disallowed.
> 3. int typed variables can resolve a parameter type of float So
> calling requiresAFloat(10) will work even in strict mode.
>
> As this topic has and is being discussed to death, I have put a very
> large "discussion points" section:
> https://wiki.php.net/rfc/scalar_type_hints_v5#discussion_points
>
> I would kindly ask, before replying that you check to see if your
> question is answered in that list.
>
> If it is not, please follow up here and I will update the RFC.
>
> If your question is listed and you feel that it wasn't given proper
> due, please let's discuss that.
>
> https://wiki.php.net/rfc/scalar_type_hints_v5
>
> Considering this proposal is a minor tweak on an already-discussed and
> voted-on proposal, I plan on bringing this RFC to vote 1 week from
> today (on February 25th, 2015).
>
> Thanks,
>
> Anthony

---

## #83130 — Leigh — 2015-02-18T22:28:31+00:00

URL: https://externals.io/message/83117#83130 · In reply to: #83129

On 18 February 2015 at 22:21, Albert Casademont Filella
<albertcasademont@gmail.com> wrote:
> So I propose 3 voting options: Yes (strict), Yes (weak), No. The Yes votes
> combined need 2/3 of the votes. Then a simple majority of 50%+1 between the
> different Yes votes is needed.

This is pretty flawed, but nice try.

---

## #83132 — Anthony Ferrara — 2015-02-18T22:37:06+00:00

URL: https://externals.io/message/83117#83132 · In reply to: #83129

Albert,

On Wed, Feb 18, 2015 at 5:21 PM, Albert Casademont Filella
<albertcasademont@gmail.com> wrote:
> Hi Anthony!
>
> Thanks for bringing this up again. I am asking you the same I asked Andrea 2
> weeks ago on Twitter: make it a triple option vote please. She didn't want
> to do it, hope you do! This way you eliminate the neverending discussion
> about weak vs strict, let the votes decide and see who really prefers weak
> type hinting only and who prefers the stricter way, both camps will have an
> option to vote.
>
> So I propose 3 voting options: Yes (strict), Yes (weak), No. The Yes votes
> combined need 2/3 of the votes. Then a simple majority of 50%+1 between the
> different Yes votes is needed.

Thanks for the feedback. I have added it to the discussion points:
https://wiki.php.net/rfc/scalar_type_hints_v5#this_proposal_should_have_multiple_vote_options

The text:

This is not a two-part proposal. The proposal is of a unified system
that was designed to work together. As such, neither part (weak-only
or strict-only) is designed to stand on its own without the other
part.

Therefore, it only makes sense to vote on this proposal as a whole.
Therefore, the voting options this RFC will present will be: Yes and
No.


Thanks,

Anthony

---

## #83133 — Christoph Becker — 2015-02-18T23:09:18+00:00

URL: https://externals.io/message/83117#83133 · In reply to: #83117

Anthony Ferrara wrote:

> 3. int typed variables can resolve a parameter type of float So
> calling requiresAFloat(10) will work even in strict mode.

Have you considered the overflow behavior of ints resulting in a float?
 For instance, the following code would produce E_RECOVERABLE_ERROR, AIUI:

  <?php

  declare(strict_types=1);

  function foo(int a, int b) {
    bar(a * b);
  }

  function bar(int n) {
  }

  foo(10000000000, 10000000000);

It seems to me that this behavior is hard to deal with generally for
programmers as well as static analyzers.  Andreas' bigint RFC[1] would
solve that issue, but it has been withdrawn, and AFAIK nobody is working
on it.  OTOH, bigint would make the widening from int to float
potentially even more lossy (i.e. inaccurate) than it is now (64bit ints
vs. IEEE 754 doubles).

IIRC, Pascal does not promote int to float on overflow, but rather
discards the high bits (unless overflow checking is enabled; available
only in some "newer" dialects).  I don't know how Java handles this
case, but I assume there's no promotion to float either.

[1] <https://wiki.php.net/rfc/bigint>

-- 
Christoph M. Becker

---

## #83135 — Anthony Ferrara — 2015-02-18T23:21:06+00:00

URL: https://externals.io/message/83117#83135 · In reply to: #83133

Christoph,



> Anthony Ferrara wrote:
>
> > […]
>
> Have you considered the overflow behavior of ints resulting in a float?
>  For instance, the following code would produce E_RECOVERABLE_ERROR, AIUI:
>
>   <?php
>
>   declare(strict_types=1);
>
>   function foo(int a, int b) {
>     bar(a * b);
>   }
>
>   function bar(int n) {
>   }
>
>   foo(10000000000, 10000000000);
>
> It seems to me that this behavior is hard to deal with generally for
> programmers as well as static analyzers.  Andreas' bigint RFC[1] would
> solve that issue, but it has been withdrawn, and AFAIK nobody is working
> on it.  OTOH, bigint would make the widening from int to float
> potentially even more lossy (i.e. inaccurate) than it is now (64bit ints
> vs. IEEE 754 doubles).
>
> IIRC, Pascal does not promote int to float on overflow, but rather
> discards the high bits (unless overflow checking is enabled; available
> only in some "newer" dialects).  I don't know how Java handles this
> case, but I assume there's no promotion to float either.
>
> [1] <https://wiki.php.net/rfc/bigint>
>

That is a very good point. We had discussed that a while ago, but it
hasn't come up in a while here. I've added a section in the RFC on it:
https://wiki.php.net/rfc/scalar_type_hints_v5#integer_overflow_to_float_behavior

Basically, I don't see any sane alternative but to have it cause an
error at runtime. It's not precision loss, it's magnitude loss.

The only other thing I can think of is to have the operators not
promote in strict mode, but that's even worse since now you're
clamping and not even giving the ability to detect it.

I don't think in practice it will be a huge issue, but even if it
comes up, it'll at least error sanely...

Thanks

Anthony

---

## #83137 — Lester Caine — 2015-02-19T00:53:28+00:00

URL: https://externals.io/message/83117#83137 · In reply to: #83133

> It seems to me that this behavior is hard to deal with generally for
> programmers as well as static analyzers.  Andreas' bigint RFC[1] would
> solve that issue, but it has been withdrawn, and AFAIK nobody is working
> on it.  OTOH, bigint would make the widening from int to float
> potentially even more lossy (i.e. inaccurate) than it is now (64bit ints
> vs. IEEE 754 doubles).

The 'unconstrained integer' RFC adds it' own problems, but the int ->
float overflow is only a problem with 32bit builds anyway. 64bit builds
will not overflow until they run out of space anyway.

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

---

## #83138 — Christoph Becker — 2015-02-19T01:23:09+00:00

URL: https://externals.io/message/83117#83138 · In reply to: #83135

Anthony,

Anthony Ferrara wrote:

> 
>
> > […]
>
> That is a very good point. We had discussed that a while ago, but it
> hasn't come up in a while here. I've added a section in the RFC on it:
> https://wiki.php.net/rfc/scalar_type_hints_v5#integer_overflow_to_float_behavior

Thanks for adding a respective note to the RFC, because IMHO it's quite
important to consider the behavior.  Somehow I would like to have
Scheme's numeric system, but that doesn't seem to fit well with type
hinting (neither strict nor weak) -- at least not when it's about
performance.

> Basically, I don't see any sane alternative but to have it cause an
> error at runtime. It's not precision loss, it's magnitude loss.
> 
> The only other thing I can think of is to have the operators not
> promote in strict mode, but that's even worse since now you're
> clamping and not even giving the ability to detect it.
> 
> I don't think in practice it will be a huge issue, but even if it
> comes up, it'll at least error sanely...

ACK.

-- 
Christoph M. Becker

---

## #83139 — Christoph Becker — 2015-02-19T01:33:52+00:00

URL: https://externals.io/message/83117#83139 · In reply to: #83137

Lester Caine wrote:

> 
> > […]
> 
> The 'unconstrained integer' RFC adds it' own problems, but the int ->
> float overflow is only a problem with 32bit builds anyway. 64bit builds
> will not overflow until they run out of space anyway.

It seems to me you're thinking too much (maybe only?) about "database
types".  IMHO PHP can be used more versatile, and there might be issues
which are exemplified in the RFC[1]:

  var_dump(2 ** 64); // float(1.844674407371E+19)

Clearly an int->float overflow that'll also happen on 64bit builds.

[1]
<https://wiki.php.net/rfc/scalar_type_hints_v5#integer_overflow_to_float_behavior>

-- 
Christoph M. Becker

---

## #83142 — Dennis Birkholz — 2015-02-19T04:21:52+00:00

URL: https://externals.io/message/83117#83142 · In reply to: #83117

Am 18.02.2015 um 21:44 schrieb Anthony Ferrara:
> Since the resignation of Andrea, the mixed-mode type hint (called
> declaration in the proposal) proposal has been left abandoned.
> Considering that the ending votes were 67/34 (66.3%) with several
> no-votes being only due to reasonably minor issues with the proposal,
> I would like to re-propose her RFC with three minor modifications:

What about Sara's "Scalar Type Hints v0.4" discussion? I find it
disturbing that you take over the RFC without even mentioning this
discussion. Please coordinate with Sara first before starting another
attempt that will be doomed because some people rather wait for Sara's
RFC and a "<?php // strict" option.

Thanks
Dennis

---

## #83143 — Dennis Birkholz — 2015-02-19T04:44:19+00:00

URL: https://externals.io/message/83117#83143 · In reply to: #83142

Am 19.02.2015 um 05:21 schrieb Dennis Birkholz:
> Am 18.02.2015 um 21:44 schrieb Anthony Ferrara:
> > […]
> 
> What about Sara's "Scalar Type Hints v0.4" discussion? I find it
> disturbing that you take over the RFC without even mentioning this
> discussion. Please coordinate with Sara first before starting another
> attempt that will be doomed because some people rather wait for Sara's
> RFC and a "<?php // strict" option.

I just saw the reddit where you mention that v0.4 is practically
abandoned now, so I will just renounce my previous mail!

Will you consider to let the people vote on how to enable strict mode
like discussed in the v0.4 discussion? Like this here from the "Reviving
scalar type hints" thread?

Am 17.02.2015 um 00:58 schrieb Sara Golemon:> Straw poll:
> 1) <?php strict;
> 2) <?php-strict
> 3) use strict; (psuedo-namespace)
> 4) <?php // strict (I don't actually like HHVM's style, but if you do...)
> 5) declare(strict=true); (As a top-level declare only)
> 6) declare(strict=true); (exactly as in v0.3 -- maybe you liked it)
> 7) your write-in vote here

Thanks
Dennis

---

## #83148 — Rick Widmer — 2015-02-19T07:12:10+00:00

URL: https://externals.io/message/83117#83148 · In reply to: #83139

> It seems to me you're thinking too much (maybe only?) about "database
> types".  IMHO PHP can be used more versatile, and there might be issues
> which are exemplified in the RFC[1]:

Maybe PHP can be more versatile, but what percentage of PHP code sits 
between a web browser and a SQL database?

I think it is pretty high!

---

## #83159 — Dmitry Stogov — 2015-02-19T09:06:40+00:00

URL: https://externals.io/message/83117#83159 · In reply to: #83125

On Thu, Feb 19, 2015 at 12:50 AM, Anthony Ferrara <ircmaxell@gmail.com>
wrote:

> Leigh,
>
> > […]
>
> I agree 100%. I just think that's outside the scope of this proposal.
>
> > […]
>
> Java does exactly this and is statically analyzable. So...?
>

PHP is not a language for static analyzes or verification!!!
Strict typing shouldn't be done on language level.
it may be implemented as a custom verification extension, but please, don't
break the language itself.

Thanks. Dmitry.



>
> > […]
>
> I missed that discussion point, so I've just added it:
>
> https://wiki.php.net/rfc/scalar_type_hints_v5#why_not_add_an_ini_setting_for_default_mode
>
> > […]
>
> Thanks for the input :-)
>
> Anthony

---

## #83164 — Lester Caine — 2015-02-19T09:36:21+00:00

URL: https://externals.io/message/83117#83164 · In reply to: #83139

> Lester Caine wrote:
> 
> > […]
> 
> It seems to me you're thinking too much (maybe only?) about "database
> types".  IMHO PHP can be used more versatile, and there might be issues
> which are exemplified in the RFC[1]:
> 
>   var_dump(2 ** 64); // float(1.844674407371E+19)
> 
> Clearly an int->float overflow that'll also happen on 64bit builds.
> 
> [1]
> <https://wiki.php.net/rfc/scalar_type_hints_v5#integer_overflow_to_float_behavior>

You see this has nothing to do with 'Scalar Type Declarations' ... this
is a problem in it's own right that needs sorting as part of the general
64bit 'upgrading' and providing a proper fix for 64bit numbers is
something which the 'unconstrained integer' RFC addressed but in my book
it was always the wrong fix, and providing a cross platform fix for
BIGINT which provides a simple integer value is the correct fix. The
voting on that RFC seemed to agree. We need 64bit values in several
places where simply clipping to 32bit ones is no longer the correct fix.

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

---

## #83167 — Lester Caine — 2015-02-19T10:04:23+00:00

URL: https://externals.io/message/83117#83167 · In reply to: #83143

> I just saw the reddit where you mention that v0.4 is practically
> abandoned now, so I will just renounce my previous mail!

DO NOT USE OTHER CHANNELS!

With the large number of secondary channels the only place that
suggestions like that should be made is here and as far as I have seen
both ideas are still 'active'? But I do find it crass that there is now
a different document with no reference to the v4 history!

What does need unravelling is just which bits go with which discussion
across all of the areas. I'm still looking at how any of this applies to
the values in the arrays I'm passing around and just getting more and
more confused. What I think I want is a set of functions to replace all
this casting mess. Rather than is_bool ... as_bool similarly as_int64
rather than getting an automatic float. I want to ask to look at a
variable in the array as the type I need for the job in hand now you may
say that is 'casting' but you are not providing me with the casts *I*
and many other database users need.

I can see the 'advantage' of optimizing code via this strict stuff that
some people want, but I don't see that has any place in a 'run only'
version of PHP. If you want to compile the code then use a port of PHP
that is compiled. Leave those of use who prefer the more dynamic system
which may well have to deal differently with a scalar variable depending
on what is returned at runtime.

On the minus side of this drive to 'optimize' the code is the potential
for completely different code on 32bit systems over 64bit ones. If the
number is below 32bit then a completely different set of code gets used
using only 32bit instructions. This may well be good for speed, but can
introduce cross platform differences that may be difficult to debug. We
currently live with those problems already with the int->float agro on
64bit numbers.

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

---

## #83171 — francois@php.net — 2015-02-19T11:58:30+00:00

URL: https://externals.io/message/83117#83171 · In reply to: #83167

> De : Lester Caine [mailto:lester@lsces.co.uk]
> 
> 
> > […]
> 
> DO NOT USE OTHER CHANNELS!

Agreed.

And the RFC was not abandoned at all. I and others have been working almost continuously on a 'compromise' single-mode approach during the last 3 days (and nights), as activity on the list shows with no doubt. So,  pretending the RFC to be 'abandoned' is just a way to discard a disagreed work.

As long as she does not officially gives up (posting to the list), I'll keep considering Sara still has the lead on scalar type hinting. If she officially gives up, I'll immediately propose to take it over and, if we are several to want it, we'll discuss.

That's the rule and I encourage list members to explicitly show their support to the formal process we all agreed upon.

For the rest, Lester summarized quite well my view about designing PHP for static analysis, instead of static analysis for PHP ;)

Regards

François

---

## #83176 — Anthony Ferrara — 2015-02-19T12:51:47+00:00

URL: https://externals.io/message/83117#83176 · In reply to: #83171

Francois and Lester (and all),

Please keep this thread on-topic. It should be for technical
discussions around this RFC only. If you have something non-technical
to discuss, please start a new topic.

Thanks

Anthony


> > […]
>
> Agreed.
>
> And the RFC was not abandoned at all. I and others have been working almost continuously on a 'compromise' single-mode approach during the last 3 days (and nights), as activity on the list shows with no doubt. So,  pretending the RFC to be 'abandoned' is just a way to discard a disagreed work.
>
> As long as she does not officially gives up (posting to the list), I'll keep considering Sara still has the lead on scalar type hinting. If she officially gives up, I'll immediately propose to take it over and, if we are several to want it, we'll discuss.
>
> That's the rule and I encourage list members to explicitly show their support to the formal process we all agreed upon.
>
> For the rest, Lester summarized quite well my view about designing PHP for static analysis, instead of static analysis for PHP ;)
>
> Regards
>
> François

---

## #83178 — Anthony Ferrara — 2015-02-19T13:01:52+00:00

URL: https://externals.io/message/83117#83178 · In reply to: #83143

Dennis,

> Will you consider to let the people vote on how to enable strict mode
> like discussed in the v0.4 discussion? Like this here from the "Reviving
> scalar type hints" thread?

I believe that RFCs should be opinionated. I dislike the recent trend
around having a lot of voting options as it only complicates things
for the voter.

For this reason I have chosen what I think is technically the best
option and went from there. I am definitely open to changing that, but
it would need to be based on technical reasons and not just "popular
preference". Heck, in a recent public poll, over 20% of respondents
voted for it being an ini setting.

I touched on the reasons in the RFC:
https://wiki.php.net/rfc/scalar_type_hints_v5#why_not_use_use_strict_instead_of_declare

But let me go through them one-by-one:

> Am 17.02.2015 um 00:58 schrieb Sara Golemon:> Straw poll:
> > […]

This is new syntax, which is potentially ambiguous around what
"strictness" is being applied. It limits future compatibility.

Additionally, it's potentially ambiguous if a file starts with <?=
strict; 4; ?>. Is that setting strict mode for a file and outputting
4? Or is it outputting the constant "strict"? Sure, this could be
"solved" with a rule that it could only follow <?php, but that starts
to get arbitrary and potentially confusing, given the other ways to
open PHP tags.

> > […]

STRONG -1, as it leaves potential for code disclosure if run on a
earlier version of PHP.

> > […]

Re-using namespaces to effect runtime is weird. Not to mention what's
the expected behavior of block mode:

<?php
namespace Foo {
    use strict;
}

namespace {
    bar();
}
?>

is bar() called in strict mode? Or in non-strict mode?

> > […]

Comments should not affect runtime behavior. HHVM uses it as they need
to affect behavior while remaining compatible with PHP. We do not have
that problem.

> > […]

Which had a number of people against it, with arguments about the odd
behavior of declare in blocks, etc.

> > […]

The only other one I've seen that *might* make sense is using a strict
qualifier on the namespace declaration:

strict namespace Foo {
}

IMO this has the same issues as use strict above. However, it also
seems to imply that the namespace is strict, where it's only the
declarations in the file that are.


I'm 100% open to technical arguments and justification to switch to
another syntax. I don't believe that it should be a poll though.
That's why I made a decision and backed it up. If anyone has logical
arguments or disagrees, let's discuss it. That way the proposal can be
improved through collaboration rather than just a blind vote.

Thanks for the feedback!!!

Anthony

---

## #83186 — Dennis Birkholz — 2015-02-19T14:07:19+00:00

URL: https://externals.io/message/83117#83186 · In reply to: #83178

Hello Anthony,

Am 19.02.2015 um 14:01 schrieb Anthony Ferrara:
> I believe that RFCs should be opinionated. I dislike the recent trend
> around having a lot of voting options as it only complicates things
> for the voter.

I just thought giving a vote on how to enable strict mode would enable a
few more people to actually vote yes. I myself can not vote but I really
hope we get scalar type hints in what kind soever into PHP 7. So keep on
and thank you for taking over.

Greets
Dennis

---

## #83198 — Robert Stoll — 2015-02-19T15:13:54+00:00

URL: https://externals.io/message/83117#83198 · In reply to: #83117

Hey Anthony,

> -----Ursprüngliche Nachricht-----
> Von: Anthony Ferrara [mailto:ircmaxell@gmail.com]
> Gesendet: Mittwoch, 18. Februar 2015 21:45
> An: internals@lists.php.net
> Betreff: [PHP-DEV] [RFC-Discuss] Scalar Type Declarations v0.5
> 
> Dear Internals,
> 
> Since the resignation of Andrea, the mixed-mode type hint (called declaration in the proposal) proposal has been left
> abandoned.
> Considering that the ending votes were 67/34 (66.3%) with several no-votes being only due to reasonably minor issues with
> the proposal, I would like to re-propose her RFC with three minor modifications:
> 
> 1. declare(strict_types=1) (if used) is required to be the first instruction in the file only. No other usages allowed.
> 2. declare(strict_types=1) {} (block mode) is specifically disallowed.
> 3. int typed variables can resolve a parameter type of float So calling requiresAFloat(10) will work even in strict mode.
> 
> As this topic has and is being discussed to death, I have put a very large "discussion points" section:
> https://wiki.php.net/rfc/scalar_type_hints_v5#discussion_points
> 
> I would kindly ask, before replying that you check to see if your question is answered in that list.
> 
> If it is not, please follow up here and I will update the RFC.
> 
> If your question is listed and you feel that it wasn't given proper due, please let's discuss that.
> 
> https://wiki.php.net/rfc/scalar_type_hints_v5
> 
> Considering this proposal is a minor tweak on an already-discussed and voted-on proposal, I plan on bringing this RFC to
> vote 1 week from today (on February 25th, 2015).
> 
> Thanks,
> 
> Anthony
> 
> --
>  

I have some questions:

you wrote: "aliases are removed (integer and boolean)"
what about the aliases real and double?

You wrote: "behaviour of weak type checks: float -> int *Only non-NaN floats between `PHP_INT_MIN` and `PHP_INT_MAX` accepted. (New in PHP 7, see the ZPP Failure on Overflow RFC)"
What about INF? Can `INF` be passed or not and if so, how is it converted?

Personally I would be stricter and disallow int->bool, float->bool, string->bool as well as bool -> int, bool -> float and bool -> string (at least for this RFC)
Why? 
1. I already mentioned the common if(strpos(..)){} case but is something which none of the RFC addressed so far and probably goes too far (you wrote "In addition to userland functions, the strict type checking mode also affects extension and built-in PHP functions:" but control structures are not affected, right?)
2. It supports an inconsistency in PHP which we should try to get away with rather than promoting it. Following an example:

function foo(string $x){ 
  var_dump($x);
  bar($x);
}
function bar(bool $x){
  var_dump($x);
  baz($x);
}
function baz(string $x){
  var_dump($x);}
foo(0);

and the output would be:

string(1) "0"
bool(false)
string(0) ""

Sure, removing the implicit conversions from and to bool do not pretend that the same would happen if one uses manual conversions instead. Yet, IMO we should forbid the implicit conversion from and to bool now and add it later on with consistent conversion rules. This way we have more time to think about a clean solution and adding implicit conversion from and to bool should also not be a BC break in 7.1

Another example:

function foo(int $x){
  var_dump($x);
  bar($x);
}
function bar(string $x){
  var_dump($x);
}
foo(false);
bar(false);

and output:

int(0)
string(1) "0"
string(0) ""

I think you get the inconsistency I am writing about.


About widening. It is not clear from the RFC if widening is only applied for int -> float or also for bool -> int, bool -> float respectively.

Cheers,
Robert

---

## #83248 — Anthony Ferrara — 2015-02-19T22:58:36+00:00

URL: https://externals.io/message/83117#83248 · In reply to: #83198

Robert,

> you wrote: "aliases are removed (integer and boolean)"
> what about the aliases real and double?

They were never part of Andrea's proposal. So they were never accepted anyway.

> You wrote: "behaviour of weak type checks: float -> int *Only non-NaN floats between `PHP_INT_MIN` and `PHP_INT_MAX` accepted. (New in PHP 7, see the ZPP Failure on Overflow RFC)"
> What about INF? Can `INF` be passed or not and if so, how is it converted?

Please see the other RFC: https://wiki.php.net/rfc/zpp_fail_on_overflow

Namely: The special floating-point values `INF` and -INF fail the check
like any other number that is too large.

> Personally I would be stricter and disallow int->bool, float->bool, string->bool as well as bool -> int, bool -> float and bool -> string (at least for this RFC)
> Why?
> 1. I already mentioned the common if(strpos(..)){} case but is something which none of the RFC addressed so far and probably goes too far (you wrote "In addition to userland functions, the strict type checking mode also affects extension and built-in PHP functions:" but control structures are not affected, right?)

This only affects function calls. Not control structures.

> 2. It supports an inconsistency in PHP which we should try to get away with rather than promoting it. Following an example:
>
> function foo(string $x){
>   var_dump($x);
>   bar($x);
> }
> function bar(bool $x){
>   var_dump($x);
>   baz($x);
> }
> function baz(string $x){
>   var_dump($x);}
> foo(0);
>
> and the output would be:
>
> string(1) "0"
> bool(false)
> string(0) ""
>
> Sure, removing the implicit conversions from and to bool do not pretend that the same would happen if one uses manual conversions instead. Yet, IMO we should forbid the implicit conversion from and to bool now and add it later on with consistent conversion rules. This way we have more time to think about a clean solution and adding implicit conversion from and to bool should also not be a BC break in 7.1

Simple: don't use weak mode. This proposal does not invent the weak
mode rules, it simply exposes them from ZPP (how it's implemented in
all internal functions) to userland hints.

So any change there would be outside of scope for this proposal and
should be made as another proposal. I will add this to the discussion
points section.

> Another example:
>
> function foo(int $x){
>   var_dump($x);
>   bar($x);
> }
> function bar(string $x){
>   var_dump($x);
> }
> foo(false);
> bar(false);
>
> and output:
>
> int(0)
> string(1) "0"
> string(0) ""
>
> I think you get the inconsistency I am writing about.
>
>
> About widening. It is not clear from the RFC if widening is only applied for int -> float or also for bool -> int, bool -> float respectively.

It's explicitly stated: "This means that parameters that declare float
can also accept int."

I will clarify this as well.

Thanks!

Anthony

---

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