# [VOTE][RFC] Scalar Type Hinting with Cast

- Thread: https://externals.io/message/77167
- Original archive: https://news-web.php.net/php.internals/77167
- Started by Andrea Faulds on 2014-09-13T23:30:40+00:00
- Messages: 46
- RFC: Add scalar type hinting with casts (Withdrawn) — https://externals.io/rfc/scalar_type_hinting_with_cast.md
- Page 1 of 2: messages 1 to 25 (25 per page, add `?page=N` to the URL)
- Next page: https://externals.io/message/77167.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

---

## #77167 — Andrea Faulds — 2014-09-13T23:30:40+00:00

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

Good evening,

I’ve given up on my plan B, so I’m putting this RFC, finally, to a vote.

I would urge you to vote in favour. It is not going to please everyone, it is after all a compromise proposal. However, I have tried my best to strike a balance between complete weak typing and strict typing. If this passes, we will finally have userland type specifiers for scalar types. It’s not perfect, but I’d argue it’s far better than nothing.

Voting starts today, 2014-09-14, and ends in a week’s time, 2014-09-21.

Thanks!

https://wiki.php.net/rfc/scalar_type_hinting_with_cast#vote
--
Andrea Faulds
http://ajf.me/

---

## #77168 — Andrea Faulds — 2014-09-13T23:35:28+00:00

URL: https://externals.io/message/77167#77168 · In reply to: #77167

> Good evening,
> 
> I’ve given up on my plan B, so I’m putting this RFC, finally, to a vote.
> 
> I would urge you to vote in favour. It is not going to please everyone, it is after all a compromise proposal. However, I have tried my best to strike a balance between complete weak typing and strict typing. If this passes, we will finally have userland type specifiers for scalar types. It’s not perfect, but I’d argue it’s far better than nothing.
> 
> Voting starts today, 2014-09-14, and ends in a week’s time, 2014-09-21.
> 
> Thanks!
> 
> https://wiki.php.net/rfc/scalar_type_hinting_with_cast#vote

I have postponed the vote after further thought. It’s been a while since this was discussed on the list.

However, it is my intent to open voting properly at some point soon, if all goes to plan.

--
Andrea Faulds
http://ajf.me/

---

## #77169 — Alain Williams — 2014-09-14T00:07:18+00:00

URL: https://externals.io/message/77167#77169 · In reply to: #77167

> Good evening,
> 
> I’ve given up on my plan B, so I’m putting this RFC, finally, to a vote.
> 
> I would urge you to vote in favour. It is not going to please everyone, it is after all a compromise proposal. However, I have tried my best to strike a balance between complete weak typing and strict typing. If this passes, we will finally have userland type specifiers for scalar types. It’s not perfect, but I’d argue it’s far better than nothing.
> 
> Voting starts today, 2014-09-14, and ends in a week’s time, 2014-09-21.
> 
> Thanks!
> 
> https://wiki.php.net/rfc/scalar_type_hinting_with_cast#vote

You give an option for float to int casting to truncate.
You give an example of truncating a positive float in that it rounds down
towards 0 - ie 1.5 becomes 1.

What happens with negaitve numbers ? Do you round towards zero or round in a
negative direction ? So, should -1.5 become -1 or -2 ? Or should it depend on
the floating point unit on the machine (not all do the same) ?

Currently PHP (CentOS on an AMD CPU) a cast to int converts -1.5 to -1.

-- 
Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
+44 (0) 787 668 0256  http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php
#include <std_disclaimer.h

---

## #77170 — Andrea Faulds — 2014-09-14T00:10:20+00:00

URL: https://externals.io/message/77167#77170 · In reply to: #77169

> You give an option for float to int casting to truncate.

Where?

    oa-res-27-90:php-src ajf$ sapi/cli/php -r 'function foobar(int $a) { var_dump($a); } foobar(1.5);'
    
    Catchable fatal error: Argument 1 passed to foobar() must be of the type int, float given, called in Command line code on line 1 and defined in Command line code on line 1

If you mean under possible changes, it’s not a change that’s been made. It’d only be worth discussing within the context of making it truncate or round.

--
Andrea Faulds
http://ajf.me/

---

## #77171 — Stas Malyshev — 2014-09-14T06:32:50+00:00

URL: https://externals.io/message/77167#77171 · In reply to: #77170

Hi!

> oa-res-27-90:php-src ajf$ sapi/cli/php -r 'function foobar(int $a) {
> var_dump($a); } foobar(1.5);'
> 
> Catchable fatal error: Argument 1 passed to foobar() must be of the
> type int, float given, called in Command line code on line 1 and
> defined in Command line code on line 1

Calling this "scalar type hinting with cast" when it doesn't actually
cast in wide variety of cases sounds a bit misleading to me. It should
be called "scalar type checking with restricted casting" or something
like that.

I would also ask to clean up an RFC a bit and to clarify which of the
proposed choices and "possible changes" are actually being voted for
when somebody votes "yes".

In any case, I call everybody to vote against this RFC in this form,
since it introduces inconsistency between internal and user functions
and makes PHP have two different arbitrary sets of rules for implicit
conversions, and this can not be good for PHP.
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/

---

## #77174 — Pierre Joye — 2014-09-14T09:12:22+00:00

URL: https://externals.io/message/77167#77174 · In reply to: #77167

hi Andrea,


> Good evening,
>
> I’ve given up on my plan B, so I’m putting this RFC, finally, to a vote.
>
> I would urge you to vote in favour. It is not going to please everyone, it is after all a compromise proposal. However, I have tried my best to strike a balance between complete weak typing and strict typing. If this passes, we will finally have userland type specifiers for scalar types. It’s not perfect, but I’d argue it’s far better than nothing.
>
> Voting starts today, 2014-09-14, and ends in a week’s time, 2014-09-21.

Great job!

It brings also some clarity and sense to type casting, at least for this area.

I do not see much of a problem with the small delta with existing
casting. I am not sure about the recoverable error, especially when
old codes will use new implementations, it may have a bad impact
depending on how the errors are a managed in a given library. But
there is no BC per se in existing codes due to this.

All in all, I will vote +1. No matter what we think what PHP should
do, remain or be, this addition has been a long due request from the
waste majority of our users. Let see what they think about it.
Hopefully some lead devs of the major tools/libs/frameworks will post
their views here.

Cheers.
-- 
Pierre

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

---

## #77175 — Alain Williams — 2014-09-14T09:12:36+00:00

URL: https://externals.io/message/77167#77175 · In reply to: #77170

> 
> 
> 
> > […]
> 
> Where?

    Possible Changes

    Float to Int Casting Rules

...

    This could be relaxed for semi-representable values. So 1.5 could be allowed
    for an int parameter (casted to 1).

-- 
Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
+44 (0) 787 668 0256  http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php
#include <std_disclaimer.h

---

## #77176 — Pierre Joye — 2014-09-14T09:16:12+00:00

URL: https://externals.io/message/77167#77176 · In reply to: #77175

> 
> > […]
>
>     Possible Changes
>
>     Float to Int Casting Rules
>
> ...
>
>     This could be relaxed for semi-representable values. So 1.5 could be allowed
>     for an int parameter (casted to 1).

That's one thing I do not like much. If one accepts both int and
float, numeric should be used instead. But allowing float for int and
raises warnings on data losses is just awkward imho.

-- 
Pierre

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

---

## #77177 — Thomas . — 2014-09-14T10:26:12+00:00

URL: https://externals.io/message/77167#77177 · In reply to: #77167

> From: ajf@ajf.me
> Date: Sun, 14 Sep 2014 00:30:40 +0100
> To: internals@lists.php.net
> Subject: [PHP-DEV] [VOTE][RFC] Scalar Type Hinting with Cast
> 
> Good evening,
> 
> I’ve given up on my plan B, so I’m putting this RFC, finally, to a vote.
> 
> I would urge you to vote in favour. It is not going to please everyone, it is after all a compromise proposal. However, I have tried my best to strike a balance between complete weak typing and strict typing. If this passes, we will finally have userland type specifiers for scalar types. It’s not perfect, but I’d argue it’s far better than nothing.
> 
> Voting starts today, 2014-09-14, and ends in a week’s time, 2014-09-21.
> 
> Thanks!
> 
> https://wiki.php.net/rfc/scalar_type_hinting_with_cast#vote
> --
> Andrea Faulds
> http://ajf.me/
> 
> 

RE: [PHP-DEV] [VOTE][RFC] Scalar Type Hinting with CastThomas Punt  11:23 To: Andrea Faulds> From: ajf@ajf.me
> Date: Sun, 14 Sep 2014 00:30:40 +0100
> To: internals@lists.php.net
> Subject: [PHP-DEV] [VOTE][RFC] Scalar Type Hinting with Cast
> 
> Good evening,
> 
> I’ve given up on my plan B, so I’m putting this RFC, finally, to a vote.
> 
> I would urge you to vote in favour. It is not going to please everyone, it is after all a compromise proposal. However, I have tried my best to strike a balance between complete weak typing and strict typing. If this passes, we will finally have userland type specifiers for scalar types. It’s not perfect, but I’d argue it’s far better than nothing.
> 
> Voting starts today, 2014-09-14, and ends in a week’s time, 2014-09-21.
> 
> Thanks!
> 
> https://wiki.php.net/rfc/scalar_type_hinting_with_cast#vote
> --
> Andrea Faulds
> http://ajf.me/
> 
> 

From a user-land developer perspective, I really detest this feature being added into PHP. If PHP has features that will make it a stronger-typed language, then it will undoubtedly lose its loosely-typed and forgiving nature eventually. The evangelists for making PHP a strongly-typed language will boast of its benefits (which will have some truth, in all fairness), and this will only lead to the condemnation of PHP code that doesn't use these stricter language features (slowly converting PHP into a stricter language). This isn't the easy-going and generally-liked nature of the PHP language in _any_ way. Whilst I can see there are benefits of making PHP stricter, I for one would rather keep PHP as a loosely-typed and forgiving language. After all, if I wanted to use a strongly-typed language for building websites, then I'd be using Java instead.
The only part of the discussion I liked on this topic was the ability to use explicit type casts as part of the function signature. Whilst it is a bit of a syntactic sugar (which will cut out on some PHP code in the function body too), it does give the function parameters some sort of signature that will show their expected set of values (assuming developers know the casting rules, of course).
-Tom
(P.s sorry for the double email Andrea, I accidentally sent this to you only the first time...)

---

## #77178 — Andrea Faulds — 2014-09-14T12:08:03+00:00

URL: https://externals.io/message/77167#77178 · In reply to: #77171

> 
> 
> Calling this "scalar type hinting with cast" when it doesn't actually
> cast in wide variety of cases sounds a bit misleading to me. It should
> be called "scalar type checking with restricted casting" or something
> like that.

I'd agree it's not the best name. This is mainly a decision to make when this is documented or added to the language spec. If we change this thing's name, we should perhaps stop calling typed parameters 'type hints'.

> I would also ask to clean up an RFC a bit and to clarify which of the
> proposed choices and "possible changes" are actually being voted for
> when somebody votes "yes".

The vote would be for the RFC as it is. Possible changes are things in the RFC I was uncertain on. I might hold votes on some of them, actually.

> In any case, I call everybody to vote against this RFC in this form,
> since it introduces inconsistency between internal and user functions
> and makes PHP have two different arbitrary sets of rules for implicit
> conversions, and this can not be good for PHP.

I had abandoned the RFC for this reason. However I gave up trying to improve zpp and make it consistent with user land hints, or adding user land hints which match zpp.

The problem is that we *can't* be consistent. Internal functions already live in this completely different world from user land functions. Nullability is handled differently. They use implicit casts in places as if they were user land functions with no parameter types at all. In other places they have strongly typed parameters. If they are passed invalid data, they usually just return `NULL` and emit a warning, though this depends on the function. User land functions, by contrast, will emit a recoverable error if the wrong type is passed. To make these two consistent would require massive backwards-compatibility breaks.

If we're just talking about casting, then this proposal does not alter casting behaviour, in fact I've been very careful not to touch it. It does, however, only accept a subset of the values zpp usually does. This is because it is a compromise between strict and weak parameter typing. While I understand you might like it to be fully weak like zpp, many userland developers are in favour of something stricter, thus the compromise. Unlike zpp's rules, at least these rules are clearly specified and prevent data loss.

Thanks!
--
Andrea Faulds
http://ajf.me/

---

## #77179 — Zeev Suraski — 2014-09-14T12:17:32+00:00

URL: https://externals.io/message/77167#77179 · In reply to: #77178

> -----Original Message-----
> From: Andrea Faulds [mailto:ajf@ajf.me]
> Sent: Sunday, September 14, 2014 3:08 PM
> To: Stas Malyshev
> Cc: internals@lists.php.net
> Subject: Re: [PHP-DEV] [VOTE][RFC] Scalar Type Hinting with Cast
>
>
> The problem is that we *can't* be consistent. Internal functions already
live in
> this completely different world from user land functions. Nullability is
handled
> differently. They use implicit casts in places as if they were user land
functions
> with no parameter types at all. In other places they have strongly typed
> parameters. If they are passed invalid data, they usually just return
 `NULL` and
> emit a warning, though this depends on the function. User land
functions, by
> contrast, will emit a recoverable error if the wrong type is passed. To
make
> these two consistent would require massive backwards-compatibility
breaks.

I honestly don't see why we can't be consistent for the simple types, or
at least strive to be as consistent as possible as opposed to introducing
a complete parallel universe for userland functions, that's inconsistent
with the entirety of the rest of PHP.  We don't have to be consistent with
ALL internal functions, which obviously have the option of doing custom
checks and return failures not only if you fail to, say, pass on a string
- but also if that string is not of a special format.  But then, you have
the option of doing that also in userland functions using custom code.
The question is not the customized cases - it's the standard behavioral
cases - comparing zpp rules for scalars and the newly-introduced rules for
userland scalars.

We could definitely strive to be consistent;  Introduce some changes to
the implicit casting rules for internal functions and implement the very
same rules for this brand new userland functions.  I'm definitely against
this RFC in its current form.

Zeev

---

## #77180 — Andrea Faulds — 2014-09-14T14:54:03+00:00

URL: https://externals.io/message/77167#77180 · In reply to: #77179

> I honestly don't see why we can't be consistent for the simple types, or
> at least strive to be as consistent as possible as opposed to introducing
> a complete parallel universe for userland functions, that's inconsistent
> with the entirety of the rest of PHP.  We don't have to be consistent with
> ALL internal functions, which obviously have the option of doing custom
> checks and return failures not only if you fail to, say, pass on a string
> - but also if that string is not of a special format.  But then, you have
> the option of doing that also in userland functions using custom code.
> The question is not the customized cases - it's the standard behavioral
> cases - comparing zpp rules for scalars and the newly-introduced rules for
> userland scalars.

OK, we could go for exactly what zpp does already. However, then we don’t have a compromise. We are siding with what you want, but most userland developers would prefer a strict system. While this would please you and perhaps some other folk on internals, and sure, it’d be consistent, it would not be popular with the wider PHP community. Similarly, we could go for a fully strict approach, which might please some userland developers, but wouldn’t please you.

I don’t want to go down this route. I’d prefer we compromise and keep PHP’s weakly-typed nature (an int can be accepted as a float or a string), but make it stricter (no data loss), thus arriving at a middle way.

> We could definitely strive to be consistent;  Introduce some changes to
> the implicit casting rules for internal functions and implement the very
> same rules for this brand new userland functions.  I'm definitely against
> this RFC in its current form.

I wanted to do that, but it has its problems. I do not have the time to go through and update literally thousands of tests that would be broken by zpp changes. Also, any change to zpp’s behaviour has backwards compatibility implications. There are some minor things I would like to change in zpp, which I will make an RFC for regardless of the success of this RFC (integer overflow should fail or at least raise a notice). Also, as I mentioned above, the resulting proposal would probably not please people who want strict types.

--
Andrea Faulds
http://ajf.me/

---

## #77181 — Andrey Andreev — 2014-09-14T14:56:39+00:00

URL: https://externals.io/message/77167#77181 · In reply to: #77179

Hi,

As a userland guy, I'm against this one.

It seems a bit political ... A lot of people want either strict type
hints or type casting hints, but because the people on this list can't
get to agree on any of the two, this RFC tries to make a compromise
that, IMO, satisfies nobody. It's done not for the benefit of
everybody, but just so we can say that PHP has "scalar type hints".
I've said this in the RFC discussion thread: In order to satisfy both
sides, instead of arguing which is the one and true way, just
implement both.

That is also why I suggested altering the proposed syntax here from:

    function foo(int $bar)

to:

    function foo((int) $bar)

Whether it applies more strict rules or not, this RFC is clearly about
type _casting_ hints, while the used syntax has so far only been used
for strict type hints. I know some would argue that this is a side
effect because you can't cast to a specific class type, but that's not
the point - the result is a strict type hint and that's what people
are used to. This is both inconsistent AND prevents PHP from having
strict scalar type hints in the future (because of the used syntax).

I (and I'm sure many others) would love both features separately, not
a hacky mix between the two.

Cheers,
Andrey.

---

## #77182 — Andrea Faulds — 2014-09-14T15:09:31+00:00

URL: https://externals.io/message/77167#77182 · In reply to: #77181

> It seems a bit political ... A lot of people want either strict type
> hints or type casting hints, but because the people on this list can't
> get to agree on any of the two, this RFC tries to make a compromise
> that, IMO, satisfies nobody. It's done not for the benefit of
> everybody, but just so we can say that PHP has "scalar type hints".
> I've said this in the RFC discussion thread: In order to satisfy both
> sides, instead of arguing which is the one and true way, just
> implement both.

I’m not sure it satisfies nobody. I realise a lot of people would prefer strict types, but plenty are still in favour of this as a compromise:

http://strawpoll.me/2463199/r - Might not be representative, but I held a poll on Twitter and StackOverflow. There are the results. 67 would vote in favour of strict hints (à la Hack), and 36 would vote in favour of this RFC, with only 5 willing to vote against it, versus 10 voting against strict hints. Note that the options aren’t mutually exclusive. 

> That is also why I suggested altering the proposed syntax here from:
> 
>    function foo(int $bar)
> 
> to:
> 
>    function foo((int) $bar)

But it’s not a cast. Such a syntax would be misleading. You would reasonably expect the following two functions to be equivalent:

    function foo($bar) { $bar = (int)$bar; }
    function foo((int) $bar) { }

Yet they are not equivalent at all. 

> Whether it applies more strict rules or not, this RFC is clearly about
> type _casting_ hints, while the used syntax has so far only been used
> for strict type hints.

Well, we haven’t had any scalar hints so far. It’s also worth noting that the documentation for PHP uses this style even though internal functions are not strict. Furthermore, scalar types in PHP are fundamentally different from non-scalar types. We do not have weak typing for non-scalars: there are no implicit casts between non-scalar types. However, we implicitly convert and juggle the scalar types all the time.

> I know some would argue that this is a side
> effect because you can't cast to a specific class type, but that's not
> the point - the result is a strict type hint and that's what people
> are used to. This is both inconsistent AND prevents PHP from having
> strict scalar type hints in the future (because of the used syntax).

Strict hints would still be possible with different syntax. However, I’m not sure they’re a good idea. Strict hints would be abandoning PHP’s weakly-typed nature, and would segregate userland functions into two kinds: strict and non-strict. I also don’t expect that would pass internals anyway.

I don’t think permitting multiple options is really the way forward, that sounds like the worst of both worlds. 

--
Andrea Faulds
http://ajf.me/

---

## #77183 — Andrey Andreev — 2014-09-14T15:40:21+00:00

URL: https://externals.io/message/77167#77183 · In reply to: #77182

Hi,


>
> 
>
> > […]
>
> I’m not sure it satisfies nobody. I realise a lot of people would prefer strict types, but plenty are still in favour of this as a compromise:
>
> http://strawpoll.me/2463199/r - Might not be representative, but I held a poll on Twitter and StackOverflow. There are the results. 67 would vote in favour of strict hints (à la Hack), and 36 would vote in favour of this RFC, with only 5 willing to vote against it, versus 10 voting against strict hints. Note that the options aren’t mutually exclusive.

So, basically ... the poll shows nothing. :)
I was actually looking for that link (I took part in the poll), but
couldn't find it.

> > […]
>
> But it’s not a cast. Such a syntax would be misleading. You would reasonably expect the following two functions to be equivalent:
>
>     function foo($bar) { $bar = (int)$bar; }
>     function foo((int) $bar) { }
>
> Yet they are not equivalent at all.

They are not equivalent, because of the different rules that you're
proposing here, but it is a cast. And the fact that with this RFC
_both_ would mean some kind of cast is happening, is simply bad.

> > […]
>
> Well, we haven’t had any scalar hints so far. It’s also worth noting that the documentation for PHP uses this style even though internal functions are not strict. Furthermore, scalar types in PHP are fundamentally different from non-scalar types. We do not have weak typing for non-scalars: there are no implicit casts between non-scalar types. However, we implicitly convert and juggle the scalar types all the time.

... and I responded to this in the next paragraph. Userland doesn't
case about internal differences, that's why they're called internal
and why people outside of php-internals have for so long been puzzled
why we only have array and object type hints.

> > […]
>
> Strict hints would still be possible with different syntax. However, I’m not sure they’re a good idea. Strict hints would be abandoning PHP’s weakly-typed nature, and would segregate userland functions into two kinds: strict and non-strict. I also don’t expect that would pass internals anyway.

That's exactly what I'm talking about ... we already have a syntax for
strict typing, (and I want to put an emphais on this) *regardless of
the reasons why, we do have strict type hints*. I don't understand why
everybody is pretending that PHP doesn't have that feature just
because we're talking about scalars here.

Speaking strictly from a userland perspective, using that same syntax
for something different will be inconsistent and will cause confusion.
That another syntax could be used for strict typing in the future is
just not a serious thing to say.

As for the language's nature/philosophy/direction/whatever, I had
something written about that, but chose to discard it in order to
avoid that "discussion". Everybody is tired of talking about that.

> I don’t think permitting multiple options is really the way forward, that sounds like the worst of both worlds.

You can't say it's the worst of both worlds when you have both worlds
in their entirety. And most importantly, they have always been two
separate worlds because they just don't make sense otherwise. I could
argue that this compromise RFC here is a mistake exactly because it is
trying to mix them.

Cheers,
Andrey.

---

## #77184 — Andrea Faulds — 2014-09-14T15:47:46+00:00

URL: https://externals.io/message/77167#77184 · In reply to: #77183

> ... and I responded to this in the next paragraph. Userland doesn't
> case about internal differences, that's why they're called internal
> and why people outside of php-internals have for so long been puzzled
> why we only have array and object type hints.

"Internal functions” refers to functions from extensions. It has no relation to internal*s*, the mailing list.

> That's exactly what I'm talking about ... we already have a syntax for
> strict typing, (and I want to put an emphais on this) *regardless of
> the reasons why, we do have strict type hints*. I don't understand why
> everybody is pretending that PHP doesn't have that feature just
> because we're talking about scalars here.

Nobody’s arguing we don’t already have strict type hints. I’m arguing strict hints don’t make sense for scalars. Note that we document strict (array, object) parameter types and non-strict (scalar) parameter types in the same way in our documentation.

> Speaking strictly from a userland perspective, using that same syntax
> for something different will be inconsistent and will cause confusion.
> That another syntax could be used for strict typing in the future is
> just not a serious thing to say.

Why is it "not a serious thing to say”? I don’t understand.

> You can't say it's the worst of both worlds when you have both worlds
> in their entirety.

No, you can. Allowing both options can be “the worst of both worlds”. This is just a trivial matter of semantics, though.

> And most importantly, they have always been two
> separate worlds because they just don't make sense otherwise.

Have they? We already mix strict and non-strict typing in PHP. Functions taking objects, internal or not, will error if you pass the wrong type of object. Internal functions taking scalars will not error and instead cast, at least most of the time.
--
Andrea Faulds
http://ajf.me/

---

## #77185 — Andrey Andreev — 2014-09-14T16:09:26+00:00

URL: https://externals.io/message/77167#77185 · In reply to: #77184

>
> 
>
> > […]
>
> "Internal functions” refers to functions from extensions. It has no relation to internal*s*, the mailing list.

I'm aware of that, hence why I said 'php-internals' to refer to the
mailing list. Again, userland devs don't care about that - PHP is
their language and they only care how we/they interact with it, not
what happens under the hood. Imagine for a moment that you've never
been involved in the development of PHP itself and you'll see how what
I say makes a lot of sense.

> > […]
>
> Nobody’s arguing we don’t already have strict type hints. I’m arguing strict hints don’t make sense for scalars. Note that we document strict (array, object) parameter types and non-strict (scalar) parameter types in the same way in our documentation.

And because you don't think it makes sense (and that might mean you
don't think it _now_), you're ignoring it. That's also a reason why
the documentation is done that way - nobody has thought of writing it
differently, because they didn't have to. The docs can always be
updated, but once the language changes, there's no going back.

> > […]
>
> Why is it "not a serious thing to say”? I don’t understand.

Because it's obvious that you're not even thinking of that as a
possibility. What would that syntax be? "function foo([int] $bar)" ?

As I already said, we already have and use a syntax for strict typing.
This RFC uses that same syntax for something different and that's
wrong, hence why the RFC should be changed, not the other way around.

> > […]
>
> No, you can. Allowing both options can be “the worst of both worlds”. This is just a trivial matter of semantics, though.

I'll ... just say that it's also the best of both worlds and agree to
disagree, I think you got the idea.

> > […]
>
> Have they? We already mix strict and non-strict typing in PHP. Functions taking objects, internal or not, will error if you pass the wrong type of object. Internal functions taking scalars will not error and instead cast, at least most of the time.

I already noted multiple times that I'm talking as a userland
developer and that no userland developer (generally speaking, of
course) cares about internal functions.

Cheers,
Andrey.

---

## #77186 — Andrea Faulds — 2014-09-14T16:17:16+00:00

URL: https://externals.io/message/77167#77186 · In reply to: #77185

> I'm aware of that, hence why I said 'php-internals' to refer to the
> mailing list. Again, userland devs don't care about that - PHP is
> their language and they only care how we/they interact with it, not
> what happens under the hood.

Yes. Internal functions are used by userland developers. Userland developers *do* care about internal functions. If we get rid of `explode()` or `json_decode()` tomorrow, userland developers *will* complain.

Perhaps I should explain what an “internal function” is in PHP parlance. An internal function is one which is exposed to userland, but is implemented in C via an extension, rather than in PHP. Examples include literally every function in PHP’s documentation.

> > […]
> 
> Because it's obvious that you're not even thinking of that as a
> possibility. What would that syntax be? "function foo([int] $bar)" ?

function foo(int! $bar)

Though it’s true, I don’t want to have them.

> As I already said, we already have and use a syntax for strict typing.
> This RFC uses that same syntax for something different and that's
> wrong, hence why the RFC should be changed, not the other way around.

I know you have a problem with using similar syntax for non-strict typing, but I don’t.

--
Andrea Faulds
http://ajf.me/

---

## #77187 — Andrey Andreev — 2014-09-14T16:41:17+00:00

URL: https://externals.io/message/77167#77187 · In reply to: #77186

>
> 
>
> > […]
>
> Yes. Internal functions are used by userland developers. Userland developers *do* care about internal functions. If we get rid of `explode()` or `json_decode()` tomorrow, userland developers *will* complain.
>
> Perhaps I should explain what an “internal function” is in PHP parlance. An internal function is one which is exposed to userland, but is implemented in C via an extension, rather than in PHP. Examples include literally every function in PHP’s documentation.

So why are we talking about "internal functions" at all? And what does
that have to do with type hints?

We know that `explode()` accepts strings, integers, floats ... we know
that's called type juggling. Strict type hints or type cast hints
wouldn't affect that. All we want is to be able to do the following:

    function foo(int $bar) {} // don't accept anything that's not an integer
    function foo((int) $bar) {} // cast $bar to an integer (if
possible, of course)

(you can ignore the syntax for that example)

That is what we want to be able to write in in a PHP application,
deffinately NOT what should be done to what I call "native" PHP
functions or "internal" PHP functions to you. We just assume those
functions don't have any kind of type hints and nobody has a problem
with that.

Cheers,
Andrey.

---

## #77188 — Dan Ackroyd — 2014-09-14T17:23:37+00:00

URL: https://externals.io/message/77167#77188 · In reply to: #77167

Hi Andrea,

When you re-open the voting, please can you have an option that is
'Yes - without numeric typehint' ?

Although I like the idea of the RFC, having a type-hint that matches
multiple scalar types seems distinctly weird to me.

It really needs a separate case making for it, separate from the
'should we have scalar type hints for the current types' question.

cheers
Dan


> Good evening,
>
> I’ve given up on my plan B, so I’m putting this RFC, finally, to a vote.
>
> I would urge you to vote in favour. It is not going to please everyone, it is after all a compromise proposal. However, I have tried my best to strike a balance between complete weak typing and strict typing. If this passes, we will finally have userland type specifiers for scalar types. It’s not perfect, but I’d argue it’s far better than nothing.
>
> Voting starts today, 2014-09-14, and ends in a week’s time, 2014-09-21.
>
> Thanks!
>
> https://wiki.php.net/rfc/scalar_type_hinting_with_cast#vote
> --
> Andrea Faulds
> http://ajf.me/

---

## #77189 — Andrea Faulds — 2014-09-14T17:25:24+00:00

URL: https://externals.io/message/77167#77189 · In reply to: #77188

> When you re-open the voting, please can you have an option that is
> 'Yes - without numeric typehint’ ?

I was already planning that, actually. :)

> Although I like the idea of the RFC, having a type-hint that matches
> multiple scalar types seems distinctly weird to me.
> 
> It really needs a separate case making for it, separate from the
> 'should we have scalar type hints for the current types' question.

Yeah. While me and Anthony thought it was a no-brainer, I’ve since seen some opposition to it, so I’d have its own vote.
--
Andrea Faulds
http://ajf.me/

---

## #77191 — Stas Malyshev — 2014-09-14T17:29:24+00:00

URL: https://externals.io/message/77167#77191 · In reply to: #77178

Hi!

> The vote would be for the RFC as it is. Possible changes are things
> in the RFC I was uncertain on. I might hold votes on some of them,
> actually.

I'm sorry, but this makes little sense to me. There are a number of
mutually contradictory options here, how you can vote for them "as it
is"? Only one of them can be implemented in code. If everybody agrees
that one of them should be so, then just remove the others. If there's
disagreement then how people can vote "yes" having contradictory ideas
in mind? One of them would be voting "yes" for the opposite of what he
thought he's voting. If the specific choices do not matter, just choose
one of the options - if they're so insignificant nobody would care if
you end up with another. In any case, there should be a clear
understanding of what is actually proposed, instead of having 5
branching points for potentially 32 different RFCs. Or, if you
absolutely can't make up your mind you can offer the options for the
vote. But there should be some specificity.

Otherwise the vote is meaningless - it's not the vote for specific
implementation but just for some vague "let's do something I don't care
what it is" and I don't think such votes make sense. Please choose
something and put it to a vote. If it doesn't work, we can have
different try or maybe we can just see there's no consensus on this for
now, but at least we'd be clear and not think we have consensus on
something but not know what actually it is.

> The problem is that we *can't* be consistent. Internal functions
> already live in this completely different world from user land
> functions. Nullability is handled differently. They use implicit

If we can't make it work well, maybe we should clean it up first instead
of making it worse.

> If we're just talking about casting, then this proposal does not
> alter casting behaviour, in fact I've been very careful not to touch
> it. It does, however, only accept a subset of the values zpp usually

Casting while passing parameters is part of the casting behavior.

> does. This is because it is a compromise between strict and weak
> parameter typing. While I understand you might like it to be fully

Again, my opinion is that bad compromise is worse than not having any
implementation, because it closes future possibilities for better
solution. Of course, there's a risk better one would never come, so
everyone has to decide if they want "at least something" now or have a
better one latter.

> weak like zpp, many userland developers are in favour of something
> stricter, thus the compromise. Unlike zpp's rules, at least these
> rules are clearly specified and prevent data loss.

I'm not sure why is this attention to data loss. In most scenarios when
we're not talking about banking applications etc. if you expect a number
and you've got a string "123abc", treating it as 123 is fine. No
*useful* data is lost, since "abc" part passed to a numeric function is
not useful data, it's garbage. Of course, for some app if you have
garbage in data you're supposed to stop the app and wait for the human
to arrive and clean up because it's too sensitive to trust a computer to
figure it out. But in more common case just ignoring the garbage would
work fine.
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/

---

## #77192 — Andrea Faulds — 2014-09-14T17:32:06+00:00

URL: https://externals.io/message/77167#77192 · In reply to: #77191

> Hi!
> 
> > […]
> 
> I'm sorry, but this makes little sense to me. There are a number of
> mutually contradictory options here, how you can vote for them "as it
> is”?

The “possible changes” section only details possible *changes*, that is, changes to the RFC that could be made, but have not been. So you would be voting for the RFC without any of those changes. If those changes were made, they would cease to be possible changes.

--
Andrea Faulds
http://ajf.me/

---

## #77193 — Stas Malyshev — 2014-09-14T17:34:25+00:00

URL: https://externals.io/message/77167#77193 · In reply to: #77192

Hi!

> The “possible changes” section only details possible *changes*, that
> is, changes to the RFC that could be made, but have not been. So you

OK, so by "possible changes" you mean things that could have been into
RFC, but were rejected and are not part of the RFC? Then I agree it is
clear but I'd feel better if it was explicitly stated there that these
things are not part of the RFC and the vote.

-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/

---

## #77194 — Andrea Faulds — 2014-09-14T17:40:03+00:00

URL: https://externals.io/message/77167#77194 · In reply to: #77193

> Hi!
> 
> > […]
> 
> OK, so by "possible changes" you mean things that could have been into
> RFC, but were rejected and are not part of the RFC? Then I agree it is
> clear but I'd feel better if it was explicitly stated there that these
> things are not part of the RFC and the vote.

The section now says "For points I'm unsure on, this section lists possible future changes to the RFC.”.
--
Andrea Faulds
http://ajf.me/

---

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