[VOTE] Scalar Type Hints

php.internals

Andrew Faulds

11 years ago
Good evening, At long last, I’m going to put the RFC to a vote. It’s been long enough - I don’t think there needs to be, or will be, much further discussion. I’d like to make sure that everyone voting understands the RFC fully. Please read the RFC in full: the details are important. And if anyone has any questions or uncertainties, please ask them before voting. I am very happy to answer them. I would urge everyone who wants type hints to vote for this RFC. It is not a perfect solution, but there can be no perfect solution to this issue. However, I think it is better than most of the alternatives suggested thus far - see the rationale section, and previous discussions. Crucially, this RFC would keep PHP a weakly-typed language, and not force either strict typing, nor weak typing, on anyone who does not want it. It would allow the addition of type hints to existing codebases. It would not create a situation where userland functions are strict yet internal functions are not, because the strict mode affects both. I’ve tested the implementation myself on my own code, and it worked well, providing benefits other proposals would not have given (see my previous post about my experiences). Voting starts today (2015-02-05) and ends in two weeks’ time (2015-02-19). In addition to the vote on the main RFC, there is also a vote on the type aliases issue, and a vote to reserve the type names for future RFCs’ sake if this RFC fails. The RFC can be found here, and it contains a voting widget: https://wiki.php.net/rfc/scalar_type_hints Thank you for your time.
-- Andrea Faulds http://ajf.me/

Andi Gutmans

11 years ago
I have to say I’m pretty disappointed at the opening of the vote. We had a pretty good RFC (thank you) for weak type hinting which was aligned with the spirit of PHP and everyone was able to rally around it. This has now been morphed into something very hard to swallow and IMO having such a declare(…) syntax will be ridiculed by the broader app dev community until the end of time… But even that syntax aside (it’s only syntax after all), I think we lost the ability to reach consensus on something so important to everyone which we haven’t been able to come to agreement on for over 10 years. Finally it was there, in reach and you made a 180 degree turn. I think it’d be so much easier for us to implement weak type hinting. Have everyone rally around it. Be happy and then learn and see whether an additional mechanism is really necessary. We could even add an E_STRICT_TYPES error_reporting flag to help folks “debug” their code if they so wish to see if there are any hotspots in their code they may want to take a look at - again not necessarily an error but maybe a debugging tool. But net, net - why not just implement the thing everyone can agree on. Have something really good in the spirit of the PHP Language for PHP 7 and learn how people leverage that… The reality is that for the majority of the Web community “1” coming in from HTTP should be accepted as a 1. Period. I voted “no” but I will vote “yes” for the competing RFC which is 80% of your RFC. Why are we not given that option?????? Andi

Unnamed Person

11 years ago
I think the consensus is not so far away. As far as I understand the rules, it is possible to vote yes and put up a new RFC to remove strict-declare after the voting ends? Regards Thomas Andi Gutmans wrote on 06.02.2015 00:22:

Andi Gutmans

11 years ago
I am not sure. I think we need to explicitly vote on a weak type hinting option. Andrea, I think this should be an option in any vote. Right now it feels like the only option to people is the very challenging, non-consensus driving RFC or nothing. I think we have plenty of key folks who would support weak type hinting and frankly, I think that would be a huge win for everyone! If I need to put forward a separate weak type hinting RFC which would heavily plagiarize Andrea's good work then please let me know. Andi On Thu, Feb 5, 2015 at 3:44 PM, Thomas Bley <mails@thomasbley.de> wrote:

Andrew Faulds

11 years ago
Hi Andi,
> On 5 Feb 2015, at 23:50, Andi Gutmans <andi@zend.com> wrote: > > I am not sure. > > I think we need to explicitly vote on a weak type hinting option. > Andrea, I think this should be an option in any vote. Right now it feels like the only option to people is the very challenging, non-consensus driving RFC or nothing. > I think we have plenty of key folks who would support weak type hinting and frankly, I think that would be a huge win for everyone!
Yes, *you* think it’s a huge win for everyone. There are plenty who’d disagree. This RFC is a different attempt at consensus. Rather than asserting the dominance of one idea over the other and completely ignoring the segment of the community that believes in a particular approach, it allows using both approaches. It allows choice. It’s radical, sure, but I think trying to accommodate everyone’s use cases (or at least most people’s) is better than covering only one of two.
-- Andrea Faulds http://ajf.me/

Andi Gutmans

11 years ago
On Thu, Feb 5, 2015 at 3:53 PM, Andrea Faulds <ajf@ajf.me> wrote:
> Hi Andi, > > > On 5 Feb 2015, at 23:50, Andi Gutmans <andi@zend.com> wrote: > > > > I am not sure. > > > > I think we need to explicitly vote on a weak type hinting option. > > Andrea, I think this should be an option in any vote. Right now it feels > like the only option to people is the very challenging, non-consensus > driving RFC or nothing. > > I think we have plenty of key folks who would support weak type hinting > and frankly, I think that would be a huge win for everyone! > > Yes, *you* think it’s a huge win for everyone. There are plenty who’d > disagree. > > This RFC is a different attempt at consensus. Rather than asserting the > dominance of one idea over the other and completely ignoring the segment of > the community that believes in a particular approach, it allows using both > approaches. It allows choice. It’s radical, sure, but I think trying to > accommodate everyone’s use cases (or at least most people’s) is better than > covering only one of two. >
Just to be clear, I think it's a thoughtful RFC. I don't think it's dumb. I can even see where you're coming from on trying to balance the approaches. I do think we should also represent the weak type hinting only folks in a ballot too. Andi

Andrew Faulds

11 years ago
Hi Andi,
> On 5 Feb 2015, at 23:22, Andi Gutmans <andi@zend.com> wrote: > > I have to say I’m pretty disappointed at the opening of the vote. > We had a pretty good RFC (thank you) for weak type hinting which was aligned with the spirit of PHP and everyone was able to rally around it.
This is far from true. Some people on internals were happy, but only some, and everywhere outside internals I looked, the reception was far more negative.
> This has now been morphed into something very hard to swallow and IMO having such a declare(…) syntax will be ridiculed by the broader app dev community until the end of time…
Nobody mocks Perl or JS for use strict.
> But even that syntax aside (it’s only syntax after all), I think we lost the ability to reach consensus on something so important to everyone which we haven’t been able to come to agreement on for over 10 years. Finally it was there, in reach and you made a 180 degree turn.
“Consensus” is exaggerated. There was no consensus and to claim there was is to ignore the reality that the PHP community is divided over this issue. I’d love to say that everyone loves weak type hints and if that version had passed we’d all be dancing around happy holding hands, but the reception was not uniformly positive, not even close, and that’s just on internals.
> I think it’d be so much easier for us to implement weak type hinting. Have everyone rally around it. Be happy and then learn and see whether an additional mechanism is really necessary.
Who’d be happy? I realise you and Zeev are big fans of weak types, as are many others, but there are also a lot of PHP developers who vehemently disagree with you.
> We could even add an E_STRICT_TYPES error_reporting flag to help folks “debug” their code if they so wish to see if there are any hotspots in their code they may want to take a look at - again not necessarily an error but maybe a debugging tool.
Global error handlers affect all code the interpreter runs, which is why we’ve looked down on them in recent times.
> But net, net - why not just implement the thing everyone can agree on.
Everyone doesn’t agree on it. If everyone did agree on it, v0.1 of the RFC would have been the one that went to vote.
> Have something really good in the spirit of the PHP Language for PHP 7 and learn how people leverage that… The reality is that for the majority of the Web community “1” coming in from HTTP should be accepted as a 1. Period.
It’s very well and good you claiming that the “majority” agree, but this does not match my experiences. The PHP community is not a single, homogenous entity. It is very difficult to judge.
> I voted “no” but I will vote “yes” for the competing RFC which is 80% of your RFC. Why are we not given that option??????
Because I cannot in good conscience push through something in the name of “consensus” which does not even approach it.
-- Andrea Faulds http://ajf.me/

Andi Gutmans

11 years ago
The folks who really want all this great strict typing should head over to Oracle.com and download free open-source Java? I hear it's got a lot of strict typing features in it. Only downside is that it'll take them 10x longer to complete their projects. OK sorry. Had to say that :) I realize it's not the same... Andrea, while I don't agree with what you say I accept it. *But* exactly for the reasons you state (the big divide) we should also have a weak type hinting option to vote for in parallel. If you feel morally unable to do that then I can copy your work and just have another RFC running in parallel but I think that would do a disservice to the good work you've done. Andi On Thu, Feb 5, 2015 at 3:47 PM, Andrea Faulds <ajf@ajf.me> wrote:

Andrew Faulds

11 years ago
Hi Andi,
> On 5 Feb 2015, at 23:57, Andi Gutmans <andi@zend.com> wrote: > > The folks who really want all this great strict typing should head over to Oracle.com and download free open-source Java? I hear it's got a lot of strict typing features in it. Only downside is that it'll take them 10x longer to complete their projects. OK sorry. Had to say that :) I realize it's not the same…
I don’t think it’s terribly funny to tell a large portion of the PHP community to go away.
> Andrea, while I don't agree with what you say I accept it. *But* exactly for the reasons you state (the big divide) we should also have a weak type hinting option to vote for in parallel. If you feel morally unable to do that then I can copy your work and just have another RFC running in parallel but I think that would do a disservice to the good work you've done.
No, I don’t think that’s fair. I’d be against holding a vote on strict types only for the same reason: the community is divided. Letting one side “win" is simply unfair on everyone else. To quote myself in the Scalar Type Hints thread, here’s a rough tally of who was in favour of what in the v0.1 thread (I think “yourself” was Zeev in that context):
> On 15 Jan 2015, at 14:51, Andrea Faulds <ajf@ajf.me> wrote: > > Let’s have a look. From a quick skim over the thread for v0.1: > > * In favour of weak types (or the RFC anyway): Adam, Stas, yourself, Jordi, Pierre, > * Against, in favour of strict types: Maxime, Nikita, Markus, Marco, Leigh, Levi, Sven(?) > * In favour of strict types, not against weak types as compromise: Matthew > * Somewhat in favour: Sebastian > * In favour of allowing both approaches: Marcio, Thomas, Marco > > I apologise if I am misrepresenting anyone’s position. > > This is unlikely to be super-representative of the PHP community. However, I’m not sure I’d say “overwhelmingly positive”. It can be easy to get confirmation bias when reading RFC threads. > > It is very clear to me that a lot of people would like strict types, and some people would like weak types. As to their relative numbers, I cannot say. > > I don’t think it’s really fair to cover only the use case of one half of the PHP community. The other half counts too. This is a rather divisive issue.
As is rather clear, there was no such consensus on internals. Confirmation bias can be a powerful thing, and it’s easy to forget that the number of messages doesn’t reflect the number of participants. The views on other places were, from my experience, even more against weak types than internals. Internals seems to be the most pro-weak types PHP community I’m a part of. Because of this schism, I really think it would be completely unfair to force through weak types. I know internals might like it (or some of internals, anyway), and I know you and Zeev certainly do, but it’s not as clear-cut in the wider community. This isn’t some minor issue, either: it’s a very frequently resurfacing topic, and one which is particularly divisive. It’s not some minor syntax issue that merely holding a vote will solve.
-- Andrea Faulds http://ajf.me/

Andi Gutmans

11 years ago
On Thu, Feb 5, 2015 at 4:05 PM, Andrea Faulds <ajf@ajf.me> wrote:
> Hi Andi, > > > On 5 Feb 2015, at 23:57, Andi Gutmans <andi@zend.com> wrote: > > > > The folks who really want all this great strict typing should head over > to Oracle.com and download free open-source Java? I hear it's got a lot of > strict typing features in it. Only downside is that it'll take them 10x > longer to complete their projects. OK sorry. Had to say that :) I realize > it's not the same… > > I don’t think it’s terribly funny to tell a large portion of the PHP > community to go away. >
Oh come on... You're taking me a bit too literally. Your proposal isn't Java-like strict typing... I even said that.
> > Andrea, while I don't agree with what you say I accept it. *But* exactly > for the reasons you state (the big divide) we should also have a weak type > hinting option to vote for in parallel. If you feel morally unable to do > that then I can copy your work and just have another RFC running in > parallel but I think that would do a disservice to the good work you've > done. > > No, I don’t think that’s fair. I’d be against holding a vote on strict > types only for the same reason: the community is divided. Letting one side > “win" is simply unfair on everyone else. >
I don't understand that statement. You mean it's not OK for any side to win unless you win? Or are you saying that you tried to strike a balance between the two parties which you hoped everyone could rally around? What if they can't? It's all or nothing? Btw, not trying to be facetious but really trying to understand where you're coming from.
> To quote myself in the Scalar Type Hints thread, here’s a rough tally of > who was in favour of what in the v0.1 thread (I think “yourself” was Zeev > in that context): >
Zeev and I aren't twins (thank god for him) and aren't always in agreement on such topics. Looks like I am not on that list. Don't see him either btw... Anyway, I think I need to sleep on it... I understand what you're trying to do. It's definitely not a crazy strict type hinting approach (which would be very bad)... But I find elements of it challenging... Andi

Andrew Faulds

11 years ago
Hi,
> On 6 Feb 2015, at 00:24, Andi Gutmans <andi@zend.com> wrote: > > Oh come on... You're taking me a bit too literally. Your proposal isn't > Java-like strict typing... I even said that.
I still disagree with the sentiment, but never mind. I realise it was just a joke.
>> No, I don’t think that’s fair. I’d be against holding a vote on strict >> types only for the same reason: the community is divided. Letting one side >> “win" is simply unfair on everyone else. > > I don't understand that statement. You mean it's not OK for any side to win > unless you win? Or are you saying that you tried to strike a balance > between the two parties which you hoped everyone could rally around?
The latter.
> What > if they can't? It's all or nothing? Btw, not trying to be facetious but > really trying to understand where you're coming from.
I just don’t feel comfortable if only one camp is satisfied. It doesn’t seem fair. While first-past-the-post politics is “winner takes it all” (usually, anyway… but that’s way off topic), the design of the PHP programming language shouldn’t be. Compromise doesn’t lead to ideal solutions, sure, but it does lead to more people being happy than otherwise, if it’s a good compromise.
>> To quote myself in the Scalar Type Hints thread, here’s a rough tally of >> who was in favour of what in the v0.1 thread (I think “yourself” was Zeev >> in that context): > > Zeev and I aren't twins (thank god for him) and aren't always in agreement > on such topics. Looks like I am not on that list. Don't see him either > btw…
huh? Maybe you misunderstood me. I meant that in that list in the quote, the word “yourself” was referring to Zeev, since that’s who I was responding to in the original email (I think). I don’t think you were in that discussion - maybe you were and I missed you.
> Anyway, I think I need to sleep on it... I understand what you're trying to > do. It's definitely not a crazy strict type hinting approach (which would > be very bad)... But I find elements of it challenging…
I also have some gripes with this RFC - declare() isn’t the nicest of things to have to type on every file. But, I think it seems to work out better overall than all the numerous other proposals I’ve seen so far, and that’s why I like it. I also need sleep. Goodnight!
-- Andrea Faulds http://ajf.me/

Stelian Mocanita

11 years ago
Sending people who want to have more structure in the language to Java is downright bad, not to mention that it sounds completely dictatorial. I would just put that in the next Zend newsletter to make it clear for your customers that there is a saner option. Stelian On Fri, Feb 6, 2015 at 12:57 AM, Andi Gutmans <andi@zend.com> wrote:

Andi Gutmans

11 years ago
> On Feb 6, 2015, at 12:42 PM, Stelian Mocanita <stelianm@php.net> wrote: > > Sending people who want to have more structure in the language to Java > is downright bad, not to mention that it psounds completely dictatorial. I > would just put that in the next Zend newsletter to make it clear for your > customers that there is a saner option. >
Oh come on. I was kidding. I will remember for next time this list has no sense of humor. And just for the record this is not a zend thing. Four zenders voted based on their own beliefs - three votes were no and one was yes. So diversity here too plus a small minority of total voters who can't really move the needle much. Let's keep the conversation pragmatic. I will try and refrain from any humor. Andi

Tony Marston

11 years ago
"Stelian Mocanita" wrote in message news:CAMc0WS6+1Y-5yJW2s=mW+ynS6tN8M5iEaXe10MWnLrL0_dZUMg@mail.gmail.com...
> >On Fri, Feb 6, 2015 at 12:57 AM, Andi Gutmans <andi@zend.com> wrote: > >> The folks who really want all this great strict typing should head over >> to >> Oracle.com and download free open-source Java? I hear it's got a lot of >> strict typing features in it. Only downside is that it'll take them 10x >> longer to complete their projects. OK sorry. Had to say that :) I realize >> it's not the same... > >Sending people who want to have more structure in the language to Java >is downright bad, not to mention that it sounds completely dictatorial. I >would just put that in the next Zend newsletter to make it clear for your >customers that there is a saner option. > >Stelian >
It is not as bad as saying "PHP has been weakly typed for the past 20 years, but PHP 7 will be strictly typed, so every developer will have to change his entire codebase in order for his application to run under PHP 7". If you are one of those who "cannot" program in a language which doesn't have strict typing, then why are you using PHP in the first place? Why aren't you using Java as Andi suggested? If you want to change the typing mechanism in PHP then remember that it *IS* weakly typed whether you like it or not, and will always be so. If you want to introduce strict typing then it must be optional, and it must not interfere with any of the existing PHP 5 applications.
-- Tony Marston

Pierre Joye

11 years ago
On Feb 7, 2015 5:01 PM, "Tony Marston" <TonyMarston@hotmail.com> wrote:
> > "Stelian Mocanita" wrote in message
news:CAMc0WS6+1Y-5yJW2s=mW+ynS6tN8M5iEaXe10MWnLrL0_dZUMg@mail.gmail.com...
> >> >> On Fri, Feb 6, 2015 at 12:57 AM, Andi Gutmans <andi@zend.com> wrote: >> >>> The folks who really want all this great strict typing should head over
to
>>> Oracle.com and download free open-source Java? I hear it's got a lot of >>> strict typing features in it. Only downside is that it'll take them 10x >>> longer to complete their projects. OK sorry. Had to say that :) I
realize
>>> it's not the same... >> >> >> Sending people who want to have more structure in the language to Java >> is downright bad, not to mention that it sounds completely dictatorial. I >> would just put that in the next Zend newsletter to make it clear for your >> customers that there is a saner option. >> >> Stelian >> > > It is not as bad as saying "PHP has been weakly typed for the past 20
years, but PHP 7 will be strictly typed, so every developer will have to change his entire codebase in order for his application to run under PHP 7". If you are one of those who "cannot" program in a language which doesn't have strict typing, then why are you using PHP in the first place? Why aren't you using Java as Andi suggested?
> > If you want to change the typing mechanism in PHP then remember that it
*IS* weakly typed whether you like it or not, and will always be so. If you want to introduce strict typing then it must be optional, and it must not interfere with any of the existing PHP 5 applications. Tony, I had to resist not to jump into this but here we go. Please double check the RFC, what it does, propose and its impact by default on existing codes. Call it doing your homework. Then reconsider your reply.

Lester Caine

11 years ago
On 07/02/15 11:07, Pierre Joye wrote:
> Please double check the RFC, what it does, propose and its impact by > default on existing codes. Call it doing your homework. Then reconsider > your reply.
There has always been a continual tread of 'you do not have to use it' in a lot of what currently slows PHP down. I still see little use to reflections, but my use of docblock annotation is being damaged by the libraries I rely on 'seeing the light' and switching to the new way of working. Adding 'strict' in a manor that these third party libraries can enable it or not as they feel fit is not the point. The very nature of an integer is now in a state of flux and either libraries have to add in extra checking for overflows that simply asking is_int is no longer going to supply so mixing that up with yet more exceptions does not seem the right way to move the language forward? If some third party can use it *I* have to add it to the library of things I have to understand simply because I will end up inside that library at some point. Unless I can request a 'non-strict' version. It may surprise people if I say that I would be more than happy with a hint/check system in here that provides a practical set of types beyond a simple 'integer'. That would then replace the current set of checks I use and would remove the need to now be worrying if the integers I am passing are too big. This ALL goes back to PDO which created a wedge that has resulted in a growing number of abstraction layers for handing data from database, much of which needs a common base of scalar values in the arrays then handled in PHP, rather than creating their own versions of those scalar entries.
-- 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

Rowan Collins

11 years ago
On 5 February 2015 23:22:26 GMT, Andi Gutmans <andi@zend.com> wrote:
>having such a declare(…) syntax will be ridiculed by the broader app >dev community until the end of time…
I think that's laying it on a bit thick. It's no worse than Python's "from __future__ import", or JS's 'use strict;' (quotes included). I wish unknown declare directives were ignored, though, because it would make for a great forward-compatibility mechanism. Still, that, like the syntax format, is a decision made many years ago.

Andi Gutmans

11 years ago
OK. But maybe that's why PHP is better than those languages :) On Thu, Feb 5, 2015 at 3:49 PM, Rowan Collins <rowan.collins@gmail.com> wrote:

Pierre Joye

11 years ago
On Fri, Feb 6, 2015 at 6:22 AM, Andi Gutmans <andi@zend.com> wrote:
> I have to say I’m pretty disappointed at the opening of the vote. > We had a pretty good RFC (thank you) for weak type hinting which was aligned with the spirit of PHP and everyone was able to rally around it. > This has now been morphed into something very hard to swallow and IMO having such a declare(…) syntax will be ridiculed by the broader app dev community until the end of time… But even that syntax aside (it’s only syntax after all), I think we lost the ability to reach consensus on something so important to everyone which we haven’t been able to come to agreement on for over 10 years. Finally it was there, in reach and you made a 180 degree turn.
> I think it’d be so much easier for us to implement weak type hinting. Have everyone rally around it. Be happy and then learn and see whether an additional mechanism is really necessary. We could even add an E_STRICT_TYPES error_reporting flag to help folks “debug” their code if they so wish to see if there are any hotspots in their code they may want to take a look at - again not necessarily an error but maybe a debugging tool. > > But net, net - why not just implement the thing everyone can agree on. Have something really good in the spirit of the PHP Language for PHP 7 and learn how people leverage that… The reality is that for the majority of the Web community “1” coming in from HTTP should be accepted as a 1. Period. > > I voted “no” but I will vote “yes” for the competing RFC which is 80% of your RFC. Why are we not given that option??????
I have to agree here while I like the declare option, it should have been an option as we clearly do not have a consensus during the discussions (and will never have). Jeopardize the whole because of that sounds dangerous to me.

Andrew Faulds

11 years ago
Hi Pierre,
> On 6 Feb 2015, at 00:50, Pierre Joye <pierre.php@gmail.com> wrote: > > I have to agree here while I like the declare option, it should have > been an option as we clearly do not have a consensus during the > discussions (and will never have). Jeopardize the whole because of > that sounds dangerous to me.
Three-way votes for this type of issue are rather nightmarish. Originally, this RFC was going to have at least three separate options in the vote, but I gave up on that because of the sheer complexity. Whatever result you’d get wouldn’t be very fair and the margins wouldn’t make sense. If someone wants to make a separate RFC later for strict types or weak types or whatever, nothing would stop them. Thanks.
-- Andrea Faulds http://ajf.me/

Dan Ackroyd

11 years ago
As much as I want scalar types I'm voting no as: i) Having this code: function foo(int $numberOfRightTurns) { $x = $numberOfRightTurns * 90; return sin(deg2rad($x)) } work or blow up depending on a setting at the top of the file is horrible. ii) Having the code that I write in userland behave differently depending on how people call it, is also horrible. Additionally Andrea, I am disappointed that you opened voting without a option with the 'declare' stuff removed. This is despite myself having asked you for an vote option for just strict types directly several times. Other people have asked for a vote option that allows strict and weak types with a different syntax. I realise that the RFC as it stands is your preferred option, but just not accepting feedback during an RFC is not appropriate. I think it's clear that a lot of people want scalar types, so I hope that we can get the implementation right, but this RFC isn't it. cheers Dan On 5 February 2015 at 20:14, Andrea Faulds <ajf@ajf.me> wrote:

Andrew Faulds

11 years ago
Hi Dan,
> On 5 Feb 2015, at 23:41, Dan Ackroyd <danack@basereality.com> wrote: > > As much as I want scalar types I'm voting no as: > > i) Having this code: > > function foo(int $numberOfRightTurns) { > $x = $numberOfRightTurns * 90; > return sin(deg2rad($x)) > } > > work or blow up depending on a setting at the top of the file is horrible.
From what I’ve seen this is a rather uncommon case. Also, that code only works for some integer values and not others: the strict version is uniformly broken, the weak version is sometimes broken.
> ii) Having the code that I write in userland behave differently > depending on how people call it, is also horrible.
Your code always behaves identically.
> Additionally Andrea, I am disappointed that you opened voting without > a option with the 'declare' stuff removed. This is despite myself > having asked you for an vote option for just strict types directly > several times. Other people have asked for a vote option that allows > strict and weak types with a different syntax.
Yes, I realise you and others have asked for such things. I disagree with you there and I don’t think adding strict types to PHP is really a good idea. I’d prefer we have more rather than less consistency between userland and internals.
> I realise that the RFC as it stands is your preferred option, but just > not accepting feedback during an RFC is not appropriate.
I have listened to feedback. But listening to feedback and agreeing to any and all suggestions are not the same thing.
-- Andrea Faulds http://ajf.me/

Andrey Andreev

11 years ago
Hi Andrea, On Fri, Feb 6, 2015 at 1:51 AM, Andrea Faulds <ajf@ajf.me> wrote:
> Hi Dan, > >> On 5 Feb 2015, at 23:41, Dan Ackroyd <danack@basereality.com> wrote: >> >> ... >> >> Additionally Andrea, I am disappointed that you opened voting without >> a option with the 'declare' stuff removed. This is despite myself >> having asked you for an vote option for just strict types directly >> several times. Other people have asked for a vote option that allows >> strict and weak types with a different syntax. > > Yes, I realise you and others have asked for such things. I disagree with you there and I don’t think adding strict types to PHP is really a good idea. I’d prefer we have more rather than less consistency between userland and internals. > >> I realise that the RFC as it stands is your preferred option, but just >> not accepting feedback during an RFC is not appropriate. > > I have listened to feedback. But listening to feedback and agreeing to any and all suggestions are not the same thing. >
It's fine that you disagree. But enabling others to disagree with you via votes would've been more fair. With the available options, it's either your way or no way. Cheers, Andrey.

Adam Harvey

11 years ago
On 6 February 2015 at 04:14, Andrea Faulds <ajf@ajf.me> wrote:
> At long last, I’m going to put the RFC to a vote. It’s been long enough - I don’t think there needs to be, or will be, much further discussion.
True, and I probably won't respond to any replies to this because we don't need more noise, but I do want to explain my -1 vote. This is long and rambling. I apologise. I've posted a formatted version of this at https://gist.github.com/LawnGnome/354ca07f1799ff88fc35 in case it's easier to read. In no particular order, my issues with this RFC: ## The declare switch Adding the cognitive overhead for each file for developers to have to remember whether they have to cast a value before passing it to a function or if PHP will automagically do that for them is a bad thing. Of course, in a small, well compartmentalised file, or a single developer code base, it wouldn't be a problem. Unfortunately, a lot of PHP projects aren't that tidy. (Probably most of them, in fact.) I also disagree with the comparisons that have been drawn on Internals between `declare(strict_types=1)`, `use strict`, and `from __future__ import foo` statements. They're not the same thing at all: * `use strict` is ultimately about code quality — am I doing something dumb? * `from __future__ import foo` is ultimately about features — yes, I want to opt-in for the new shiny. * `declare(strict_types=1)` isn't either of those, although it might superficially appear so — what it's really about is "I reject your philosophy and substitute my own" in terms of typing. There are structural decisions we can and should let our users make. I believe this isn't one of them: allowing users to fundamentally change the typing semantics of a language on a module-by-module level is, in my opinion, insanity. Languages have to be opinionated about this sort of issue: if they weren't, there'd only be one programming language and it would have 800 switches to configure before you could write a line of code. This sort of decision is the whole point of designing a language: abdicating it by providing a switch is effectively us shrugging and saying "sure, whatever, we don't care, so now we'll make you care". ## Strong typing This ties into the previous point: for scalars, PHP has never been a strongly typed language. I was once on the train of strict typing being universally better — if you know that you always have an integer, you never have to worry about a bad conversion, right? And, if I was designing a language from scratch, I'd probably still feel that way. That language wouldn't be PHP, though. PHP is unapologetically weakly typed from top to bottom. Designing a feature to break that would be bad enough. Designing a feature to optionally break that is insidious. If you care about whether the zval IS_STRING, you can check that today. Encouraging our users to care goes against the entire philosophy of the language. To be clear: yes, we have problems in our type conversion matrix. The fact that `"21 Jump Street" == 21` is an issue (particularly because it's silent), and we should be talking about that. But strong typing is not the solution. ## Caller versus callee Making the caller responsible for choosing the type behaviour is a clever hack. (No pun intended, Facebookers.) I find the idea intriguing from an academic perspective. Unfortunately, as with the above point, this isn't consistent with PHP as a language that's existed for 20 years and had type hinting in its current form for over 10 years. If we accept this, then we only widen the gap between scalar values and array/object ones: for one set of type declarations, the behaviour is determined entirely by the callee, and for another, it's determined by both the callee (via the type hint) and the caller (whether it will be converted or not). ## So what do we do for 7.0? From where I sit, we had a good solution: it was the 0.1 version of this RFC. It behaved like PHP should behave, respected PHP's long standing scalar type handling and conversion rules, but most importantly, it solved the **actual** problem scalar type hints are supposed to solve in the simplest possible way: Can I guarantee that my function that expects an integer will really get an integer? I don't think that adding complexity on top of that helps anyone in the long run. Yes, we get to tick some extra boxes — "we support strong typing", "we support weak typing", "we put the user in control" — but at the cost of having a language that not only supports, but advertises multiple, inconsistent behaviours, requires users to be aware of conversion minutiae that they shouldn't have to be mindful of, and doesn't do anything to solve the actual problem above. Adam

Andi Gutmans

11 years ago
+1

François Laupretre

11 years ago
+1

Nikita Popov

11 years ago
On Thu, Feb 5, 2015 at 9:14 PM, Andrea Faulds <ajf@ajf.me> wrote:
> Good evening, > > At long last, I’m going to put the RFC to a vote. It’s been long enough - > I don’t think there needs to be, or will be, much further discussion. > > I’d like to make sure that everyone voting understands the RFC fully. > Please read the RFC in full: the details are important. And if anyone has > any questions or uncertainties, please ask them before voting. I am very > happy to answer them. > > I would urge everyone who wants type hints to vote for this RFC. It is not > a perfect solution, but there can be no perfect solution to this issue. > However, I think it is better than most of the alternatives suggested thus > far - see the rationale section, and previous discussions. Crucially, this > RFC would keep PHP a weakly-typed language, and not force either strict > typing, nor weak typing, on anyone who does not want it. It would allow the > addition of type hints to existing codebases. It would not create a > situation where userland functions are strict yet internal functions are > not, because the strict mode affects both. I’ve tested the implementation > myself on my own code, and it worked well, providing benefits other > proposals would not have given (see my previous post about my experiences). > > Voting starts today (2015-02-05) and ends in two weeks’ time (2015-02-19). > In addition to the vote on the main RFC, there is also a vote on the type > aliases issue, and a vote to reserve the type names for future RFCs’ sake > if this RFC fails. > > The RFC can be found here, and it contains a voting widget: > https://wiki.php.net/rfc/scalar_type_hints > > Thank you for your time. >
After much initial reluctance, I've voted in favor of this RFC. I'm a proponent of strict scalar typing. I will not explain the reasons behind this here, because they have been covered extensively in the previous threads and I no longer have the patience for such heavily prejudiced discussions. As such this mail is really an explanation why I am voting for an RFC defaulting to weak types, despite my misgivings with such a typing scheme. A primary appeal of this RFC is that the "strict_types" mode not only influences userland function calls, but also calls to internal functions. I really appreciate the symmetry behind this - a plain strict scalar typing proposal would only cover userland calls, while this also enforces proper type usage with internal ones. This seems very reasonable, as the same arguments in favor of strict scalar types for userland functions apply nearly identically to internal functions as well. Another advantage of this approach is that there are fewer interoperability issues between libraries using strict typing internally and external code not making use of it. A pure strict scalar typing proposal would likely cause severe integration issues between code using scalar types and code not using them at all and as such using relatively unpredictable data types. This issue will not be entirely alleviated by this proposal (primarily due to the lack of generic or semi-generic types), but it will be much more limited and libraries should be able to safely use the strict typing mode without alienating users. Lastly, I would like to talk about cognitive overhead. This RFC uses a per-file typing mode declaration and there may be concerns about having to mentally adjust to different modes being used in different files of a project. While I think this is an important concern, there are two ameliorating factors: a) It is very likely that libraries using strict scalar types will use them in the entire project rather than having a mix of different modes in different files. Similarly applications will likely also either be fully strictly typed or have clearly separated front- and backend components where only the latter uses strict scalar types. b) Within one file, this RFC actually removes mental overhead, because type declarations will behave identically for userland and internal functions. You won't have to deal with some functions being liberal and some being strict. Thanks, Nikita

Dennis Birkholz

11 years ago
Am 06.02.2015 um 21:22 schrieb Nikita Popov:
> After much initial reluctance, I've voted in favor of this RFC.
Thank you Nikita for this decision. I would really like to have any kind of scalar type hints introduced into PHP. I think most want this, but do not agree if and how type conversion should happen. I urge all people who can vote to consider if they can imagine a compromise that satisfies all parties better and if there will ever be scalar type hints in the near future if this vote fails. I am concerned the answers are probably not and no. So please vote in a way that we can have scalar type hints in the near future. Thanks to all of you for participating in this discussion and making PHP a better language! Dennis

Sebastian Bergmann

11 years ago
On 02/06/2015 10:22 PM, Nikita Popov wrote:
> After much initial reluctance, I've voted in favor of this RFC.
After reading your email, Nikita, I deleted my vote (it was no before). I will review the RFC again, with your arguments (and others) in mind and maybe I'll come to a different conclusion.

Jordi Boggiano

11 years ago
On 07/02/2015 01:08, Sebastian Bergmann wrote:
> On 02/06/2015 10:22 PM, Nikita Popov wrote: >> After much initial reluctance, I've voted in favor of this RFC. > > After reading your email, Nikita, I deleted my vote (it was no before). > I will review the RFC again, with your arguments (and others) in mind > and maybe I'll come to a different conclusion.
Thank you for that, Sebastian. It is not a simple RFC and votes should be thought through as it is such an old and important topic to many people. Cheers
-- Jordi Boggiano @seldaek - http://nelm.io/jordi

Zeev Suraski

11 years ago
> -----Original Message----- > From: Jordi Boggiano [mailto:j.boggiano@seld.be] > Sent: Sunday, February 08, 2015 8:12 PM > To: internals@lists.php.net > Subject: Re: [PHP-DEV] [VOTE] Scalar Type Hints > > On 07/02/2015 01:08, Sebastian Bergmann wrote: > > On 02/06/2015 10:22 PM, Nikita Popov wrote: > >> After much initial reluctance, I've voted in favor of this RFC. > > > > After reading your email, Nikita, I deleted my vote (it was no > > before). > > I will review the RFC again, with your arguments (and others) in mind > > and maybe I'll come to a different conclusion. > > Thank you for that, Sebastian. It is not a simple RFC and votes should be > thought through as it is such an old and important topic to many people.
Indeed it is. I think it's very clear that this RFC represents (almost) the farthest possible position from consensus, with all of the original key designers of the language strictly opposing it, as well as many others. This is one of the most polarizing votes I ever recall here. I'm not sure whether it'll get through or not, but given the intention of this RFC was to create a proposal everyone can rally behind, it very clearly failed. We didn't have to wait for a vote by the way, it was clear from the discussion on internals@. I sincerely hope that we'll gather enough votes to prevent strict typing from making it into PHP. Last, voters should take into account that this isn't an 'either this RFC or nothing' situation. I think it's very unfortunate that the original RFC - that had zero controversy surrounding it - was never put to a vote. Clearly, it didn't give the strict camp what it wanted, but on the other hand, it introduced nothing into the language that anybody considers damaging to PHP - even in the eyes of the strict camp. That cannot be said about this RFC. I'm not sure how many of the people who support the current RFC would be equally happy (or happier) with the original one, but I suspect that it's a fair number, and we'd definitely want to put it to a vote in case the current one fails to pass (and potentially even if it does pass, to give people the opportunity to choose between having the extra strict part vs. not having it, a choice they didn't get but should have). Zeev

Andrew Faulds

11 years ago
Zeev,
> On 8 Feb 2015, at 19:48, Zeev Suraski <zeev@zend.com> wrote: > > Last, voters should take into account that this isn't an 'either this RFC or > nothing' situation. I think it's very unfortunate that the original RFC - > that had zero controversy surrounding it - was never put to a vote.
Please stop repeating this, it is blatantly false and I’ve pointed this out several times.
-- Andrea Faulds http://ajf.me/

Zeev Suraski

11 years ago
> -----Original Message----- > From: Andrea Faulds [mailto:ajf@ajf.me] > Sent: Sunday, February 08, 2015 9:50 PM > To: Zeev Suraski > Cc: Jordi Boggiano; internals@lists.php.net > Subject: Re: [PHP-DEV] [VOTE] Scalar Type Hints > > Zeev, > > > On 8 Feb 2015, at 19:48, Zeev Suraski <zeev@zend.com> wrote: > > > > Last, voters should take into account that this isn't an 'either this > > RFC or nothing' situation. I think it's very unfortunate that the > > original RFC - that had zero controversy surrounding it - was never put > > to a > vote. > > Please stop repeating this, it is blatantly false and I’ve pointed this > out > several times.
It's not blatantly false, and please refrain from telling me what I can or cannot say (!) Zeev

Stas Malyshev

11 years ago
Hi!
>> Last, voters should take into account that this isn't an 'either this RFC or >> nothing' situation. I think it's very unfortunate that the original RFC - >> that had zero controversy surrounding it - was never put to a vote. > > Please stop repeating this, it is blatantly false and I’ve pointed this out several times.
How is it false? Did we have a vote on v1? What was the result of the vote?
-- Stas Malyshev smalyshev@gmail.com

Andrew Faulds

11 years ago
Hi,
> On 8 Feb 2015, at 23:03, Stanislav Malyshev <smalyshev@gmail.com> wrote: > >>> Last, voters should take into account that this isn't an 'either this RFC or >>> nothing' situation. I think it's very unfortunate that the original RFC - >>> that had zero controversy surrounding it - was never put to a vote. >> >> Please stop repeating this, it is blatantly false and I’ve pointed this out several times. > > How is it false? Did we have a vote on v1? What was the result of the vote?
No, we didn’t. But the statement “zero controversy” implies that, well… let’s look up what controversy means:
> argument that involves many people who strongly disagree about something : strong disagreement about something among a large group of people
(Merriam-Webster) So, controversy is where a lot of people disagree - and there were numerous people in the original thread who disagreed with the RFC and preferred strict types. I actually tallied them in a reply to Zeev (which I later quoted in a reply to Andi). There were almost as many people against the proposal as in favour. This is to say nothing as to how it was received outside internals which, from my experience on reddit, Twitter and StackOverflow, was even less positive than internals, considerably so. So, I think that to say that there was “zero controversy” is certainly stretching the truth. Really, I’m yet to see any scalar type hinting discussions which haven’t had some controversy.
-- Andrea Faulds http://ajf.me/

Zeev Suraski

11 years ago
> So, controversy is where a lot of people disagree - and there were > numerous > people in the original thread who disagreed with the RFC and preferred > strict > types. I actually tallied them in a reply to Zeev (which I later quoted in > a reply > to Andi). There were almost as many people against the proposal as in > favour. This is to say nothing as to how it was received outside internals > which, from my experience on reddit, Twitter and StackOverflow, was even > less positive than internals, considerably so. > > So, I think that to say that there was “zero controversy” is certainly > stretching the truth. Really, I’m yet to see any scalar type hinting > discussions > which haven’t had some controversy.
It's not stretching the truth or even slightly bending it, considering the RFC currently being voted on is a superset of that RFC. There's zero or virtually zero controversy surrounding the weak typing RFC, the one that was v0.1. The controversy wasn't (and isn't) about what was in v0.1, but rather, about what wasn't in there, namely, strict typing; Not in the contents of the v0.1 RFC itself, which, again, had zero controversy around and is effectively being voted on as an integral part of the current RFC. You have virtually all of the supporters of strict typing voting in favor of the current RFC, also voting in favor of the v0.1 elements which are an integral part of it. The way it should have went is voting on the weak typing RFC, around which there was (and probably still is) almost consensus. Right afterwards, vote on the strict elements that you added in v0.2. That would have been the one way to know what the voter base truly thinks. Right now, I believe many people are voting in favor thinking that otherwise we'd get nothing, and again - pretty much nobody is supportive of 'nothing'. Zeev

Andrew Faulds

11 years ago
Hi Zeev,
> On 8 Feb 2015, at 23:24, Zeev Suraski <zeev@zend.com> wrote: > > It's not stretching the truth or even slightly bending it, considering the > RFC currently being voted on is a superset of that RFC.
That has no relevancy.
> There's zero or virtually zero controversy surrounding the weak typing RFC, > the one that was v0.1. The controversy wasn't (and isn't) about what was in > v0.1, but rather, about what wasn't in there, namely, strict typing;
So, then, there was controversy around that RFC.
> The way it should have went is voting on the weak typing RFC, around which > there was (and probably still is) almost consensus.
Again, there was not consensus. The RFC was controversial, especially outside of internals, but even on internals around half the people who responded *were not positive*.
-- Andrea Faulds http://ajf.me/

Jordi Boggiano

11 years ago
On 08/02/2015 23:24, Zeev Suraski wrote:
> There's zero or virtually zero controversy surrounding the weak typing RFC, > the one that was v0.1. The controversy wasn't (and isn't) about what was in > v0.1, but rather, about what wasn't in there, namely, strict typing; Not in > the contents of the v0.1 RFC itself, which, again, had zero controversy > around and is effectively being voted on as an integral part of the current > RFC. You have virtually all of the supporters of strict typing voting in > favor of the current RFC, also voting in favor of the v0.1 elements which > are an integral part of it.
By this logic, the current proposal also does not take anything away from weak-typing proponents (which I guess I am a part of FWIW). It lets everyone be happy in their corner. I don't see how this is worse than one side winning by ignoring the other. Cheers
-- Jordi Boggiano @seldaek - http://nelm.io/jordi

Pierre Joye

11 years ago
On Mon, Feb 9, 2015 at 6:24 AM, Zeev Suraski <zee@zend.com> wrote:
>> So, controversy is where a lot of people disagree - and there were >> numerous >> people in the original thread who disagreed with the RFC and preferred >> strict >> types. I actually tallied them in a reply to Zeev (which I later quoted in >> a reply >> to Andi). There were almost as many people against the proposal as in >> favour. This is to say nothing as to how it was received outside internals >> which, from my experience on reddit, Twitter and StackOverflow, was even >> less positive than internals, considerably so. >> >> So, I think that to say that there was “zero controversy” is certainly >> stretching the truth. Really, I’m yet to see any scalar type hinting >> discussions >> which haven’t had some controversy. > > It's not stretching the truth or even slightly bending it, considering the > RFC currently being voted on is a superset of that RFC. > > There's zero or virtually zero controversy surrounding the weak typing RFC, > the one that was v0.1. The controversy wasn't (and isn't) about what was in > v0.1, but rather, about what wasn't in there, namely, strict typing; Not in > the contents of the v0.1 RFC itself, which, again, had zero controversy > around and is effectively being voted on as an integral part of the current > RFC. You have virtually all of the supporters of strict typing voting in > favor of the current RFC, also voting in favor of the v0.1 elements which > are an integral part of it. > > The way it should have went is voting on the weak typing RFC, around which > there was (and probably still is) almost consensus. Right afterwards, vote > on the strict elements that you added in v0.2. > > That would have been the one way to know what the voter base truly thinks. > Right now, I believe many people are voting in favor thinking that otherwise > we'd get nothing, and again - pretty much nobody is supportive of 'nothing'.
Zeev, we know it by now. You do not like it. And given past experiences nothing, virtually nothng, tells me that you will accept anything anyway. There is a vote, you do not like the RFC or part of it, vote no. But this constant attempt to get exactly what you want and do almost everything possible to get it is getting very counter productive. Not the first time but hopefully the last. Cheers,
-- Pierre @pierrejoye | http://www.libgd.org

Matthew Leverton

11 years ago
On Sun, Feb 8, 2015 at 1:48 PM, Zeev Suraski <zeev@zend.com> wrote:
> > proposal everyone can rally behind, it very clearly failed. We didn't have > to wait for a vote by the way, it was clear from the discussion on > internals@. >
Controversial RFCs are precisely the ones that SHOULD be voted on. Policy states that 2/3s means consensus on core language changes. The current 63.5% isn't too far from that. Just curious, but do you have a different number in mind for this vote? 90%? 80%?
-- Matthew Leverton

Zeev Suraski

11 years ago
> -----Original Message----- > From: Matthew Leverton [mailto:leverton@gmail.com] > Sent: Sunday, February 08, 2015 11:17 PM > To: Zeev Suraski > Cc: Jordi Boggiano; PHP internals > Subject: Re: [PHP-DEV] [VOTE] Scalar Type Hints > > On Sun, Feb 8, 2015 at 1:48 PM, Zeev Suraski <zeev@zend.com> wrote: > > > > proposal everyone can rally behind, it very clearly failed. We didn't > > have to wait for a vote by the way, it was clear from the discussion > > on internals@. > > > Controversial RFCs are precisely the ones that SHOULD be voted on.
Not really. These should be avoided as much as possible.
> Policy states that 2/3s means consensus on core language changes. The > current 63.5% isn't too far from that. Just curious, but do you have a > different number in mind for this vote? 90%? 80%?
I'm well aware of it as I wrote that policy. The goal of the policy was to prevent a situation where a temporary majority can introduce features into the language that would later on be impossible to reverse. It's not by any stretch a good mechanism to solve controversial votes, which again, should ideally be avoided as much as possible. It's just that there isn't a better mechanism. Zeev

Matthew Leverton

11 years ago
On Sun, Feb 8, 2015 at 3:22 PM, Zeev Suraski <zeev@zend.com> wrote:
> I'm well aware of it as I wrote that policy. The goal of the policy was to > prevent a situation where a temporary majority can introduce features into > the language that would later on be impossible to reverse. It's not by any > stretch a good mechanism to solve controversial votes, which again, should > ideally be avoided as much as possible. It's just that there isn't a better > mechanism. >
I know I'm unfairly paraphrasing you, but it sounds like you are saying that for things that you don't have strong feelings about, then you're fine if the others vote amongst themselves. But for things that matter to you, you want to reserve the right to prevent change. Is there a way to fairly describe what you consider too controversial to vote on? The problem I see with votes for this type of feature is that you probably have a breakdown of something like: - 10% of people don't want scalar type hints - 20% of people want both, but 50% of them would vote for either weak or strong - 35% of people want strict, but 80% of them are fine with weak - 35% of people want weak, but 80% of them are fine with strong So if a strict-only vote happens first, you get 73% to say yes. If weak-only vote happens first, you get 73% to say yes. (I'm obviously just making up these numbers with no scientific basis, but I think the principle is valid.) The only way to be fair IMO is to hold a vote where you rank those four options (weak, strong, both, neither) and hold an instant run-off vote where the first majority wins. And if 'neither' wins, then agree that the topic cannot be revisited until next major version, so that everybody can rest for 5 years. ;)
-- Matthew Leverton

Dmitry Stogov

11 years ago
this is more or less true. :( The proposal is presented in an unfair way to include strict typing without the ability to vote for weak types only. Despite of semantic arguments, the implementation is a bit immature and introduces slowdown for any code without type hints. Thanks. Dmitry. On Mon, Feb 9, 2015 at 7:20 AM, Matthew Leverton <leverton@gmail.com> wrote:

Pierre Joye

11 years ago
On Mon, Feb 9, 2015 at 3:04 PM, Dmitry Stogov <dmitry@zend.com> wrote:
> this is more or less true. :( > The proposal is presented in an unfair way to include strict typing without > the ability to vote for weak types only. > > Despite of semantic arguments, the implementation is a bit immature and > introduces slowdown for any code without type hints.
Hm, I have a bad feeling about this argument popping up again now. I did not see any significant perf degradation using common apps but I ask Matt to run some tests again using the PR vs master, let discuss actual subjective numbers instead of raising the performance impact blocker :) Cheers, Pierre

Pavel Kouřil

11 years ago
On Mon, Feb 9, 2015 at 9:04 AM, Dmitry Stogov <dmitry@zend.com> wrote:
> this is more or less true. :( > The proposal is presented in an unfair way to include strict typing without > the ability to vote for weak types only. > > Despite of semantic arguments, the implementation is a bit immature and > introduces slowdown for any code without type hints. > > Thanks. Dmitry. > >
This is something I mentioned several times - there should be two votes. One for weak types and one for adding the strict typing on the weak typing as a bonus. Not bundling it into one voting, it makes it feel "forced". Pavel Kouril

Andrew Faulds

11 years ago
Hi,
> On 9 Feb 2015, at 08:04, Dmitry Stogov <dmitry@zend.com> wrote: > > this is more or less true. :( > The proposal is presented in an unfair way to include strict typing without > the ability to vote for weak types only.
Oddly, nobody seems to complain that it's unfair if I side with the weak typing camp, despite that being equally unfair.
> Despite of semantic arguments, the implementation is a bit immature and > introduces slowdown for any code without type hints.
The implementation could do with improvement, this is true. However I suspect any slowdown is minor at best, and this could be dealt with in future. The RFC is more about the language change than the implementation.
-- Andrea Faulds http://ajf.me/

François Laupretre

11 years ago
> De : Jordi Boggiano [mailto:j.boggiano@seld.be] > Envoyé : dimanche 8 février 2015 19:12 > À : internals@lists.php.net > Objet : Re: [PHP-DEV] [VOTE] Scalar Type Hints > > On 07/02/2015 01:08, Sebastian Bergmann wrote: > > On 02/06/2015 10:22 PM, Nikita Popov wrote: > >> After much initial reluctance, I've voted in favor of this RFC. > > > > After reading your email, Nikita, I deleted my vote (it was no before). > > I will review the RFC again, with your arguments (and others) in mind > > and maybe I'll come to a different conclusion. > > Thank you for that, Sebastian. It is not a simple RFC and votes should > be thought through as it is such an old and important topic to many people.
Please send congratulations in private mails. You really don't have the sense of the ridiculous. Why don't you offer money to people to change their vote ? (just kidding but, just in case...) Do you remember that the overall objective is CONSENSUS. As Zeev already said, the only result of your insistence was to split the community into two polarized camps. Do you think we have too many people working on PHP internals ? As a consequence of the PHP 6 failure, we lost several among the most precious ones. Do you want to do the same with PHP 7 ? Regards François

Sebastian Bergmann

11 years ago
Am 07.02.2015 um 02:08 schrieb Sebastian Bergmann:
> After reading your email, Nikita, I deleted my vote (it was no before). > I will review the RFC again, with your arguments (and others) in mind > and maybe I'll come to a different conclusion.
I have voted (no) again. I still think that if we add support for scalars in type declarations then the corresponding check must be strict. But since that strictness does not align with the spirit of PHP I much rather have no support for scalars than one that is not strict. Maybe built-in classes such as String, Integer, Float, Boolean that know how convert themselves to the corresponding scalar type are a viable approach that is worth exploring.

Pierre Joye

11 years ago
On Feb 9, 2015 8:52 PM, "Sebastian Bergmann" <sebastian@php.net> wrote:
> > Am 07.02.2015 um 02:08 schrieb Sebastian Bergmann: > > After reading your email, Nikita, I deleted my vote (it was no before). > > I will review the RFC again, with your arguments (and others) in mind > > and maybe I'll come to a different conclusion. > > I have voted (no) again. > > I still think that if we add support for scalars in type declarations > then the corresponding check must be strict. But since that strictness > does not align with the spirit of PHP I much rather have no support > for scalars than one that is not strict.
Not strict? You loose me here.

Matteo Beccati

11 years ago
On 09/02/2015 15:50, Pierre Joye wrote:
> On Feb 9, 2015 8:52 PM, "Sebastian Bergmann" <sebastian@php.net> wrote: >> then the corresponding check must be strict. But since that strictness >> does not align with the spirit of PHP I much rather have no support >> for scalars than one that is not strict. > > Not strict? You loose me here.
I guess he meant: "no support for scalar type hints than one that is not strict." Cheers
-- Matteo Beccati Development & Consulting - http://www.beccati.com/

Sebastian Bergmann

11 years ago
Am 09.02.2015 um 15:50 schrieb Pierre Joye:
> Not strict? You loose me here.
I want support for scalar types in signatures. I want these type declarations to be strictly enforced. This is not wanted and not proposed by the RFC. Hence my vote.

André Rømcke

11 years ago
On 09 Feb 2015, at 16:04 , Sebastian Bergmann <sebastian@php.net> wrote:
> > Am 09.02.2015 um 15:50 schrieb Pierre Joye: >> Not strict? You loose me here. > > I want support for scalar types in signatures. I want these type > declarations to be strictly enforced. This is not wanted and not > proposed by the RFC. Hence my vote.
It is, from your point of view, the provider of a API, strictly enforced: you’ll get exactly the type you asked for. The current RFC is clever in this way, it makes sure the library author gets the types they want, and the user of it can freely choose mode as he see fit and is skilled for. I’m sure we can easily do a followup RFC to add a ini setting/argument, to be able to run unit test in strict mode by default, unless for instance code specifically declares strict_types=0. Which I guess would be great for PHPUnit runs to really get full control over what kind of types we use throughout our code. So to summarize: This RFC gets you a ton of a lot closer to the strictness you (and I), would like to use for at least our test runs.. Best, André

Lars Strojny

11 years ago
Hi Andrea,
> On 05 Feb 2015, at 21:14, Andrea Faulds <ajf@ajf.me> wrote: > [...] > Voting starts today (2015-02-05) and ends in two weeks’ time (2015-02-19). In addition to the vote on the main RFC, there is also a vote on the type aliases issue, and a vote to reserve the type names for future RFCs’ sake if this RFC fails. > > The RFC can be found here, and it contains a voting widget: https://wiki.php.net/rfc/scalar_type_hints
I realise how much effort you put into making scalar type hinting possible in PHP and I applaud you for that. Being a proponent of strict scalar type hinting I also understand the current RFC tries to find a compromise between both camps. It is probably the best we can come up with right now given we want to fullfill the following set of requirements: - Strict scalar hinting - Weak scalar hinting - Let the mode be chosen by the caller, not the callee I nevertheless decided voting against it as I am afraid the current RFC would do more long-term harm to the ecosystem than not having scalar type hints. My main concern is that the declare statement is basically a better behaviour changing ini setting and PHPs history is paved with those. I very much hope for scalar type hinting, especially a strict variant but this is not what we should merge. cu, Lars

Matteo Beccati

11 years ago
Hi Lars, On 07/02/2015 04:36, Lars Strojny wrote:
> My main concern is that the declare statement is > basically a better behaviour changing ini setting and PHPs history is > paved with those. I very much hope for scalar type hinting, > especially a strict variant but this is not what we should merge.
Maybe it's just me, but I didn't quite understand the point you are making here. Are you saying that declares are more or less like ini settings? Cheers
-- Matteo Beccati Development & Consulting - http://www.beccati.com/

Pierre Joye

11 years ago
On Feb 7, 2015 6:46 PM, "Matteo Beccati" <php@beccati.com> wrote:
> > Hi Lars, > > > On 07/02/2015 04:36, Lars Strojny wrote: >> >> My main concern is that the declare statement is >> basically a better behaviour changing ini setting and PHPs history is >> paved with those. I very much hope for scalar type hinting, >> especially a strict variant but this is not what we should merge. > > > Maybe it's just me, but I didn't quite understand the point you are
making here. Are you saying that declares are more or less like ini settings? Somehow related but for such things, a notion of package (aka the discussions we had back then about namespace vs package) would be amazingly handy here.

Lars Strojny

11 years ago
Hi Matteo, sorry for the late response.
> On 07 Feb 2015, at 12:46, Matteo Beccati <php@beccati.com> wrote: > > Maybe it's just me, but I didn't quite understand the point you are making here. Are you saying that declares are more or less like ini settings?
Yes, exactly that. The new declare()-statement will fundamentally change how the engine behaves and one will have two learn more or less two flavors of PHP. Even worse I am forced to use the PHP flavor the person picked who changed the declare() statement last. cu, Lars

Andrew Faulds

11 years ago
Hi,
> On 9 Feb 2015, at 18:22, Lars Strojny <lars@strojny.net> wrote: > >> On 07 Feb 2015, at 12:46, Matteo Beccati <php@beccati.com> wrote: >> >> Maybe it's just me, but I didn't quite understand the point you are making here. Are you saying that declares are more or less like ini settings? > > Yes, exactly that. The new declare()-statement will fundamentally change how the engine behaves
It’s a relatively minor change. It changes how arguments and return values are type-checked, that’s all. The patch isn’t that complex.
> and one will have two learn more or less two flavors of PHP.
Hardly, the differences are not that big. One’s slightly stricter when checking arguments and return values, but that’s it. It’s not two completely different worlds, it’s a minor detail of personal preference.
> Even worse I am forced to use the PHP flavor the person picked who changed the declare() statement last.
Well, yes, in a project with multiple people, you must conform to the project style guide and such, that’s hardly unusual.
-- Andrea Faulds http://ajf.me/

Philip Sturgeon

11 years ago
On Mon, Feb 9, 2015 at 1:22 PM, Lars Strojny <lars@strojny.net> wrote:
> Hi Matteo, > > sorry for the late response. > >> On 07 Feb 2015, at 12:46, Matteo Beccati <php@beccati.com> wrote: >> >> Maybe it's just me, but I didn't quite understand the point you are making here. Are you saying that declares are more or less like ini settings? > > Yes, exactly that. The new declare()-statement will fundamentally change how the engine behaves and one will have two learn more or less two flavors of PHP. Even worse I am forced to use the PHP flavor the person picked who changed the declare() statement last. > > cu, > Lars
This is strange for me to understand but I do see it come up a lot. "if you have foo(string $name), you expect strict type... if you want weak type, foo($name). All code will work as is today, no BC breaks." No. If I have foo(string $name), I expect a string. I don't care if its strong or weak, I just want a string. The weak or strong bit is up to the user, which is why they're the ones holding the switch. While I understand the wish to preach best practices to the PHP community in general - because heck knows some people need it - this is more of an entry for phptherightway.com than the job of every single library author to try and force the community ot use strict typing one library at a time. The function author doesn't need to care if its strong or weak. They just need to care that they have the right type. And they will, every time. Using foo($name) will give me the wrong types, so no thanks on that :)

Pierre Joye

11 years ago
On Feb 10, 2015 1:22 AM, "Lars Strojny" <lars@strojny.net> wrote:
> > Hi Matteo, > > sorry for the late response. > > > On 07 Feb 2015, at 12:46, Matteo Beccati <php@beccati.com> wrote: > > > > Maybe it's just me, but I didn't quite understand the point you are
making here. Are you saying that declares are more or less like ini settings?
> > Yes, exactly that. The new declare()-statement will fundamentally change
how the engine behaves and one will have two learn more or less two flavors of PHP. Even worse I am forced to use the PHP flavor the person picked who changed the declare() statement last. No. You are not.

Matt F

11 years ago
FYI, the patch doesn't cause a performance regression. I built on and tested with IIS/Windows. Performance remains the same for Wordpress, Symfony and Joomla. Mediawiki actually increased slightly (5%), so performance is increase/decrease is not an issue here, the language and engine are. If you're interested, see: http://windows.php.net/downloads/snaps/ostc/pftt/perf/results-20150209-master_rcaf5521-scalar_type_hints_2_strict_mode-8436.html Regards -M On Mon, Feb 9, 2015 at 6:43 PM, Pierre Joye <pierre.php@gmail.com> wrote:

Dmitry Stogov

11 years ago
If you measure performance impact using CPU performance counters (VTune, oprofile, perf) or even better CPU emulator (callgrind) you'll see slight degradation. It's also clear that it makes some degradation from code review. 1% difference is invisible because measurement mistake is usually bigger and also performance may change from build to build because of different code layout. Anyway, this is not a stopper, just an issue that would be great to fix. Thanks. Dmtiry. On Tue, Feb 10, 2015 at 11:09 AM, Matt Ficken <themattficken@gmail.com> wrote:

Pierre Joye

11 years ago
On Tue, Feb 10, 2015 at 4:56 PM, Dmitry Stogov <dmitry@zend.com> wrote:
> If you measure performance impact using CPU performance counters (VTune, > oprofile, perf) or even better CPU emulator (callgrind) you'll see slight > degradation. It's also clear that it makes some degradation from code > review. 1% difference is invisible because measurement mistake is usually > bigger and also performance may change from build to build because of > different code layout.
At the application level the impact is not relevant.
> Anyway, this is not a stopper, just an issue that would be great to fix.
Full ack. And I would really love to see the same kindness for this RFC and the unsolved issues it may have than the one we had for phpng. This RFC also remembers how critical it is to have a two phases RFC for such complex tasks. It is demoralizing and a waste of time to do things as we do now, for such huge thing. Cheers, Pierre

Pavel Kouřil

11 years ago
On Thu, Feb 5, 2015 at 9:14 PM, Andrea Faulds <ajf@ajf.me> wrote:
> Good evening, > > At long last, I’m going to put the RFC to a vote. It’s been long enough - I don’t think there needs to be, or will be, much further discussion. >
Hello, I just realized it now (I brought it up in a different manner when there was discussion about the RFC), but I didn't notice there was a totally false statement about it in the RFC itself. You probably should fix it. I'm speaking about the "Strict type checking, which is used by many popular programming languages, particularly ones which are statically-typed, such as Java, C#, Haskell, or Facebook's Hack. It is also used for non-scalar parameter type hints in PHP. With this approach, an argument is only accepted if its type is exactly the same as the parameter." paragraph. This is NOT true (at least for C# and Java), as you can read here in the documentations of respecitve languages so you should not compare the strict version of the typing implemented in PHP with other strongly typed languages, because the PHP's "strict" is stricter than strongly static typed languages. I really hope noone voted with the thought that the strict typing acts as it does in Java and C#. https://msdn.microsoft.com/en-us/library/y5b434w4.aspx http://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.2 Regards Pavel Kouril

Andrew Faulds

11 years ago
Hi Pavel,
> On 7 Feb 2015, at 10:57, Pavel Kouřil <pajousek@gmail.com> wrote: > > On Thu, Feb 5, 2015 at 9:14 PM, Andrea Faulds <ajf@ajf.me> wrote: >> Good evening, >> >> At long last, I’m going to put the RFC to a vote. It’s been long enough - I don’t think there needs to be, or will be, much further discussion. >> > > I just realized it now (I brought it up in a different manner when > there was discussion about the RFC), but I didn't notice there was a > totally false statement about it in the RFC itself. You probably > should fix it. I'm speaking about the "Strict type checking, which is > used by many popular programming languages, particularly ones which > are statically-typed, such as Java, C#, Haskell, or Facebook's Hack. > It is also used for non-scalar parameter type hints in PHP. With this > approach, an argument is only accepted if its type is exactly the same > as the parameter." paragraph. > > This is NOT true (at least for C# and Java), as you can read here in > the documentations of respecitve languages so you should not compare > the strict version of the typing implemented in PHP with other > strongly typed languages, because the PHP's "strict" is stricter than > strongly static typed languages. I really hope noone voted with the > thought that the strict typing acts as it does in Java and C#. > > https://msdn.microsoft.com/en-us/library/y5b434w4.aspx > http://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.2
I don’t think it’s unfair. There’s a limited set of permitted conversions in some strictly-typed languages, but it’s still strictly-typed. Thanks.
-- Andrea Faulds http://ajf.me/

Andrew Faulds

11 years ago
Hi,
> On 7 Feb 2015, at 20:47, Andrea Faulds <ajf@ajf.me> wrote: > >> On 7 Feb 2015, at 10:57, Pavel Kouřil <pajousek@gmail.com> wrote: >> >> I just realized it now (I brought it up in a different manner when >> there was discussion about the RFC), but I didn't notice there was a >> totally false statement about it in the RFC itself. You probably >> should fix it. I'm speaking about the "Strict type checking, which is >> used by many popular programming languages, particularly ones which >> are statically-typed, such as Java, C#, Haskell, or Facebook's Hack. >> It is also used for non-scalar parameter type hints in PHP. With this >> approach, an argument is only accepted if its type is exactly the same >> as the parameter." paragraph. >> >> This is NOT true (at least for C# and Java), as you can read here in >> the documentations of respecitve languages so you should not compare >> the strict version of the typing implemented in PHP with other >> strongly typed languages, because the PHP's "strict" is stricter than >> strongly static typed languages. I really hope noone voted with the >> thought that the strict typing acts as it does in Java and C#. >> >> https://msdn.microsoft.com/en-us/library/y5b434w4.aspx >> http://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.2 > > I don’t think it’s unfair. There’s a limited set of permitted conversions in some strictly-typed languages, but it’s still strictly-typed.
To add to the previous email: * Most of these conversions are between different sizes of the same type (float/double, char/short/int/long, etc.), but this is irrelevant to PHP which has only one size for each type * The other ones are between types (int to float) * Always allowing implicit conversions from float to int is very likely to cause data loss, so it’s not unreasonable for PHP to prevent this specific case * Always allowing implicit conversions from int to float is sometimes going to cause data loss, so it may also be reasonable for PHP to prevent this specific case * Requiring an exact type match has the least mental overhead, and allows types to be checked at compile-time Thanks.
-- Andrea Faulds http://ajf.me/

Pavel Kouřil

11 years ago
On Sat, Feb 7, 2015 at 9:57 PM, Andrea Faulds <ajf@ajf.me> wrote:
> Hi, > >> On 7 Feb 2015, at 20:47, Andrea Faulds <ajf@ajf.me> wrote: >> >>> On 7 Feb 2015, at 10:57, Pavel Kouřil <pajousek@gmail.com> wrote: >>> >>> I just realized it now (I brought it up in a different manner when >>> there was discussion about the RFC), but I didn't notice there was a >>> totally false statement about it in the RFC itself. You probably >>> should fix it. I'm speaking about the "Strict type checking, which is >>> used by many popular programming languages, particularly ones which >>> are statically-typed, such as Java, C#, Haskell, or Facebook's Hack. >>> It is also used for non-scalar parameter type hints in PHP. With this >>> approach, an argument is only accepted if its type is exactly the same >>> as the parameter." paragraph. >>> >>> This is NOT true (at least for C# and Java), as you can read here in >>> the documentations of respecitve languages so you should not compare >>> the strict version of the typing implemented in PHP with other >>> strongly typed languages, because the PHP's "strict" is stricter than >>> strongly static typed languages. I really hope noone voted with the >>> thought that the strict typing acts as it does in Java and C#. >>> >>> https://msdn.microsoft.com/en-us/library/y5b434w4.aspx >>> http://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.2 >> >> I don’t think it’s unfair. There’s a limited set of permitted conversions in some strictly-typed languages, but it’s still strictly-typed. > > To add to the previous email: > > * Most of these conversions are between different sizes of the same type (float/double, char/short/int/long, etc.), but this is irrelevant to PHP which has only one size for each type > * The other ones are between types (int to float) > * Always allowing implicit conversions from float to int is very likely to cause data loss, so it’s not unreasonable for PHP to prevent this specific case > * Always allowing implicit conversions from int to float is sometimes going to cause data loss, so it may also be reasonable for PHP to prevent this specific case > * Requiring an exact type match has the least mental overhead, and allows types to be checked at compile-time >
Yeah, but you say in the RFC that "With this approach, an argument is only accepted if its type is exactly the same as the parameter." when speaking about C# and Java - which is NOT true. You should have written that the way of strict typing in PHP is even more strict than Java's and C# one - because the way it's written now is unfortunately misinforming the readers of the RFC. Also, there's no need to mention float -> int, because that one is definitely wrong. But for the int (and long, etc) -> float (and double) - how do the languages you mentioned in the RFC handle that conversion? I'm wishing more and more that the RFC doesn't pass (even though I'd LOVE to have typehints in PHP as a userland developer) and someone else will make a better version of typehints RFC for PHP 7, because this one feels really like you took an ok-ish RFC (one that would be good for PHP) and slapped a strict typing on it without enough research about strong typing in other languages. And as I said myself multiple times in the past, the declare syntax IS just ugly (and changing how code works by writing one line is an ugly principle as well, IMHO). :( Regards Pavel Kouril

Andrew Faulds

11 years ago
Hi,
> On 7 Feb 2015, at 22:03, Pavel Kouřil <pajousek@gmail.com> wrote: > > On Sat, Feb 7, 2015 at 9:57 PM, Andrea Faulds <ajf@ajf.me> wrote: >> Hi, >> >>> On 7 Feb 2015, at 20:47, Andrea Faulds <ajf@ajf.me> wrote: >>> >>>> On 7 Feb 2015, at 10:57, Pavel Kouřil <pajousek@gmail.com> wrote: >>>> >>>> I just realized it now (I brought it up in a different manner when >>>> there was discussion about the RFC), but I didn't notice there was a >>>> totally false statement about it in the RFC itself. You probably >>>> should fix it. I'm speaking about the "Strict type checking, which is >>>> used by many popular programming languages, particularly ones which >>>> are statically-typed, such as Java, C#, Haskell, or Facebook's Hack. >>>> It is also used for non-scalar parameter type hints in PHP. With this >>>> approach, an argument is only accepted if its type is exactly the same >>>> as the parameter." paragraph. >>>> >>>> This is NOT true (at least for C# and Java), as you can read here in >>>> the documentations of respecitve languages so you should not compare >>>> the strict version of the typing implemented in PHP with other >>>> strongly typed languages, because the PHP's "strict" is stricter than >>>> strongly static typed languages. I really hope noone voted with the >>>> thought that the strict typing acts as it does in Java and C#. >>>> >>>> https://msdn.microsoft.com/en-us/library/y5b434w4.aspx >>>> http://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.2 >>> >>> I don’t think it’s unfair. There’s a limited set of permitted conversions in some strictly-typed languages, but it’s still strictly-typed. >> >> To add to the previous email: >> >> * Most of these conversions are between different sizes of the same type (float/double, char/short/int/long, etc.), but this is irrelevant to PHP which has only one size for each type >> * The other ones are between types (int to float) >> * Always allowing implicit conversions from float to int is very likely to cause data loss, so it’s not unreasonable for PHP to prevent this specific case >> * Always allowing implicit conversions from int to float is sometimes going to cause data loss, so it may also be reasonable for PHP to prevent this specific case >> * Requiring an exact type match has the least mental overhead, and allows types to be checked at compile-time >> > > Yeah, but you say in the RFC that "With this approach, an argument is > only accepted if its type is exactly the same as the parameter." when > speaking about C# and Java - which is NOT true.
C# and Java aren’t really considered weakly-typed. Technically they’re not “fully strict” I guess, but if you were to give example of strictly-typed languages, you’d probably include C# and Java in that list - so I did.
> You should have > written that the way of strict typing in PHP is even more strict than > Java's and C# one - because the way it's written now is unfortunately > misinforming the readers of the RFC.
It might be somewhat misleading. Really, what’s “weak” and what’s “strict” is rather subjective: C is sometimes considered weak, sometimes strict. I’d say it’s more “weak” because all sorts of definitely wrong conversions are allowed implicitly and merely generate warnings. C# and Java are more careful here, so I’d say they’re “strict” even though I suppose they do have a degree of weak typing.
> Also, there's no need to mention > float -> int, because that one is definitely wrong. But for the int > (and long, etc) -> float (and double) - how do the languages you > mentioned in the RFC handle that conversion?
From Microsoft’s documentation that you linked, it sounds like they just always convert and never error, so you’d get data loss in some cases (just like you do in PHP with an explicit cast).
> I'm wishing more and more that the RFC doesn't pass (even though I'd > LOVE to have typehints in PHP as a userland developer) and someone > else will make a better version of typehints RFC for PHP 7, because > this one feels really like you took an ok-ish RFC (one that would be > good for PHP) and slapped a strict typing on it without enough > research about strong typing in other languages.
I am familiar with other languages, I just disagree with their approach.
> And as I said myself > multiple times in the past, the declare syntax IS just ugly (and > changing how code works by writing one line is an ugly principle as > well, IMHO). :(
I prefer this approach to the inconsistency the other approaches suggested thus far lead to.
-- Andrea Faulds http://ajf.me/

Pavel Kouřil

11 years ago
On Sat, Feb 7, 2015 at 11:11 PM, Andrea Faulds <ajf@ajf.me> wrote:
> Hi, > >> On 7 Feb 2015, at 22:03, Pavel Kouřil <pajousek@gmail.com> wrote: >> >> >> Yeah, but you say in the RFC that "With this approach, an argument is >> only accepted if its type is exactly the same as the parameter." when >> speaking about C# and Java - which is NOT true. > > C# and Java aren’t really considered weakly-typed. Technically they’re not “fully strict” I guess, but if you were to give example of strictly-typed languages, you’d probably include C# and Java in that list - so I did.
C# and Java definitely aren't weakly typed. I never said they are though? Also, is there a real difference between strict and strong? Because C# refers to itself as a strongly typed, but you use "strict typing" everytime you speak about strong typing?
> > It might be somewhat misleading. Really, what’s “weak” and what’s “strict” is rather subjective: C is sometimes considered weak, sometimes strict. I’d say it’s more “weak” because all sorts of definitely wrong conversions are allowed implicitly and merely generate warnings. C# and Java are more careful here, so I’d say they’re “strict” even though I suppose they do have a degree of weak typing. > >> Also, there's no need to mention >> float -> int, because that one is definitely wrong. But for the int >> (and long, etc) -> float (and double) - how do the languages you >> mentioned in the RFC handle that conversion? > > From Microsoft’s documentation that you linked, it sounds like they just always convert and never error, so you’d get data loss in some cases (just like you do in PHP with an explicit cast). > > I am familiar with other languages, I just disagree with their approach. >
It's not somewhat misleading, it's 100% misleading - because you state that it acts like in Java and C#, but it doesn't. Also, are there any strongly typed language that implement strong/strict typing the way you want to do it in PHP?
>> And as I said myself >> multiple times in the past, the declare syntax IS just ugly (and >> changing how code works by writing one line is an ugly principle as >> well, IMHO). :( > > I prefer this approach to the inconsistency the other approaches suggested thus far lead to. >
The thing is, you cannot please everyone. When you try to please anyone, you usally end up with something that has flaws for everyone to some degree. :(

Rasmus Lerdorf

11 years ago
On 02/07/2015 05:03 PM, Pavel Kouřil wrote:
> I'm wishing more and more that the RFC doesn't pass (even though I'd > LOVE to have typehints in PHP as a userland developer) and someone > else will make a better version of typehints RFC for PHP 7, because > this one feels really like you took an ok-ish RFC (one that would be > good for PHP) and slapped a strict typing on it without enough > research about strong typing in other languages. And as I said myself > multiple times in the past, the declare syntax IS just ugly (and > changing how code works by writing one line is an ugly principle as > well, IMHO). :(
I am not sure I would go that far. Andrea did plenty of research and has tons of experience in other languages, I just think this approach is misguided. I also wonder just how many people of those who voted even bothered to download and try the patch. I tried it a while back on some existing code and it was a nightmare. Does everyone realize that these simple things break? tan(1); echo strstr("test", "est", 1); Having absolutely no coercion for int to float and 0/1 to false/true, especially for internal functions, is just too pedantic to me. I also find this a bit hypocritical: declare(strict_types=true); outputs: Fatal error: strict_types declaration must have 0 or 1 as its value That is obviously nit-picking, but if we are going to get this pedantic... And, you also have to realize that it isn't actually per file. For example, this: <?php function myErrorHandler($errno, $errstr, $errfile, $errline) { if ($errno===E_RECOVERABLE_ERROR) { echo "\ncatchable fatal error\n"; return true; } return false; } set_error_handler('myErrorHandler'); echo tan(1); declare(strict_types=1); echo tan(1); declare(strict_types=0); echo tan(1); This will output: 1.5574077246549 catchable fatal error 1.5574077246549 The RFC refers to it as a per-file directive, which just means it doesn't apply to files you include after setting it. It doesn't mean that the entire file is affected. You can flip in and out of strict mode at will. Which isn't necessarily a bad thing, but it can certainly get confusing. For example. Since everyone has already voted, you can all tell me what this does, right? 1) <?php function do_something() { declare(strict_types=1); } echo tan(1); do_something(); echo tan(1); How about this: 2) <?php echo tan(1); do_something(); echo tan(1); function do_something() { declare(strict_types=1); } or this? 3) <?php function do_something() { declare(strict_types=1); } echo tan(1); echo tan(1); Answers: 1) fatal error on the first tan(1) 2) no errors 3) same as 1) Basically declare() does not respect function scope, but it doesn't let you know that. There is a reason we haven't used declare() for anything real. -Rasmus

Pierre Joye

11 years ago
On Sun, Feb 8, 2015 at 9:38 AM, Rasmus Lerdorf <rasmus@lerdorf.com> wrote:
> On 02/07/2015 05:03 PM, Pavel Kouřil wrote: >> I'm wishing more and more that the RFC doesn't pass (even though I'd >> LOVE to have typehints in PHP as a userland developer) and someone >> else will make a better version of typehints RFC for PHP 7, because >> this one feels really like you took an ok-ish RFC (one that would be >> good for PHP) and slapped a strict typing on it without enough >> research about strong typing in other languages. And as I said myself >> multiple times in the past, the declare syntax IS just ugly (and >> changing how code works by writing one line is an ugly principle as >> well, IMHO). :( > > I am not sure I would go that far. Andrea did plenty of research and has > tons of experience in other languages, I just think this approach is > misguided. I also wonder just how many people of those who voted even > bothered to download and try the patch. I tried it a while back on some > existing code and it was a nightmare. Does everyone realize that these > simple things break? > > tan(1); > echo strstr("test", "est", 1); > > Having absolutely no coercion for int to float and 0/1 to false/true, > especially for internal functions, is just too pedantic to me. I also > find this a bit hypocritical: > > declare(strict_types=true); > > outputs: > > Fatal error: strict_types declaration must have 0 or 1 as its value > > That is obviously nit-picking, but if we are going to get this pedantic... > > And, you also have to realize that it isn't actually per file. For > example, this: > > <?php > function myErrorHandler($errno, $errstr, $errfile, $errline) { > if ($errno===E_RECOVERABLE_ERROR) { > echo "\ncatchable fatal error\n"; > return true; > } > return false; > } > set_error_handler('myErrorHandler'); > > echo tan(1); > declare(strict_types=1); > echo tan(1); > declare(strict_types=0); > echo tan(1); > > This will output: > > 1.5574077246549 > catchable fatal error > 1.5574077246549 > > The RFC refers to it as a per-file directive, which just means it > doesn't apply to files you include after setting it. It doesn't mean > that the entire file is affected. You can flip in and out of strict mode > at will. Which isn't necessarily a bad thing, but it can certainly get > confusing. > > For example. Since everyone has already voted, you can all tell me what > this does, right? > > 1) > <?php > function do_something() { > declare(strict_types=1); > } > echo tan(1); > do_something(); > echo tan(1); > > How about this: > > 2) > <?php > echo tan(1); > do_something(); > echo tan(1); > function do_something() { > declare(strict_types=1); > } > > or this? > > 3) > <?php > function do_something() { > declare(strict_types=1); > } > echo tan(1); > echo tan(1); > > Answers: > > 1) fatal error on the first tan(1) > 2) no errors > 3) same as 1) > > Basically declare() does not respect function scope, but it doesn't let > you know that. There is a reason we haven't used declare() for anything > real.
I do not see that as a blocker. Anyway, if everyone has voted then you do not have to worry as the RFC is rejected as of now. Badly but so it goes.
-- Pierre @pierrejoye | http://www.libgd.org

Andrew Faulds

11 years ago
Hi Rasmus,
> On 8 Feb 2015, at 02:38, Rasmus Lerdorf <rasmus@lerdorf.com> wrote: > > On 02/07/2015 05:03 PM, Pavel Kouřil wrote: >> I'm wishing more and more that the RFC doesn't pass (even though I'd >> LOVE to have typehints in PHP as a userland developer) and someone >> else will make a better version of typehints RFC for PHP 7, because >> this one feels really like you took an ok-ish RFC (one that would be >> good for PHP) and slapped a strict typing on it without enough >> research about strong typing in other languages. And as I said myself >> multiple times in the past, the declare syntax IS just ugly (and >> changing how code works by writing one line is an ugly principle as >> well, IMHO). :( > > I am not sure I would go that far. Andrea did plenty of research and has > tons of experience in other languages, I just think this approach is > misguided. I also wonder just how many people of those who voted even > bothered to download and try the patch. I tried it a while back on some > existing code and it was a nightmare. Does everyone realize that these > simple things break? > > tan(1); > echo strstr("test", "est", 1);
Banning int->float and float->int is both a pain point and sometimes a life-saver. It’s annoying that tan(1) doesn’t work. On the other hand, you discover if your ints floats would be silently truncated (as I did with PictoSwap). I wouldn’t say that int->string not working is a problem, though. Seeing something like strstr(“test”, “est”, 1); is rather confusing. Looking at it, I’d think the third parameter is some sort of number for you to want to pass an integer to it. If I want a string, I’ll use one.
> Having absolutely no coercion for int to float and 0/1 to false/true, > especially for internal functions, is just too pedantic to me. I also > find this a bit hypocritical: > > declare(strict_types=true); > > outputs: > > Fatal error: strict_types declaration must have 0 or 1 as its value > > That is obviously nit-picking, but if we are going to get this pedantic…
Yes, that is a cruel irony that I did notice when I changed it. I sacrificed strictness/“correctness” there for brevity. The reason you can’t use a boolean is that I think it’s better if only two forms are allowed (=0 and =1) - less forms to remember, less ambiguity.
> And, you also have to realize that it isn't actually per file. For > example, this: > > <?php > function myErrorHandler($errno, $errstr, $errfile, $errline) { > if ($errno===E_RECOVERABLE_ERROR) { > echo "\ncatchable fatal error\n"; > return true; > } > return false; > } > set_error_handler('myErrorHandler'); > > echo tan(1); > declare(strict_types=1); > echo tan(1); > declare(strict_types=0); > echo tan(1); > > This will output: > > 1.5574077246549 > catchable fatal error > 1.5574077246549 > > The RFC refers to it as a per-file directive, which just means it > doesn't apply to files you include after setting it. It doesn't mean > that the entire file is affected. You can flip in and out of strict mode > at will. Which isn't necessarily a bad thing, but it can certainly get > confusing.
Yes, the RFC is somewhat inaccurate in that respect. It is per-file in one sense (like encoding, but unlike ticks, it has no effect on the including or included files). However, it technically affects the remainder of the file, not the whole file.
> For example. Since everyone has already voted, you can all tell me what > this does, right? > > 1) > <?php > function do_something() { > declare(strict_types=1); > } > echo tan(1); > do_something(); > echo tan(1);
I don’t understand why it’s even allowed for the declare() statement to be used like that (why is a compile-time option allowed to be within a function? That’s a recipe for disaster), but that would make the first tan(1); error and halt program execution.
> How about this: > > 2) > <?php > echo tan(1); > do_something(); > echo tan(1); > function do_something() { > declare(strict_types=1); > }
First two calls succeed. Again, declare()’s behaviour is weird… makes me wonder who thought it was a good idea to allow this.
> or this? > > 3) > <?php > function do_something() { > declare(strict_types=1); > } > echo tan(1); > echo tan(1);
That would make the first tan(1); error and halt program execution.
> Answers: > > 1) fatal error on the first tan(1) > 2) no errors > 3) same as 1)
Hooray, I guessed right.
> Basically declare() does not respect function scope, but it doesn't let > you know that. There is a reason we haven't used declare() for anything > real.
I wonder if we should just remove this ability of declare(); or at least produce some sort of warning (E_DEPRECATED? E_WARNING? E_STRICT?). It’s highly misleading and I don’t really understand why it’s allowed. Then again, that would cause problems for ticks, possibly?
-- Andrea Faulds http://ajf.me/

Andrew Faulds

11 years ago
Hi,
> On 8 Feb 2015, at 02:51, Andrea Faulds <ajf@ajf.me> wrote: > > Yes, the RFC is somewhat inaccurate in that respect. It is per-file in one sense (like encoding, but unlike ticks, it has no effect on the including or included files). However, it technically affects the remainder of the file, not the whole file.
A minor follow-up: the RFC does actually mention this specific point about declare()’s behaviour:
> By default, all PHP files are in weak type-checking mode. A new declare() directive is added, strict_types, which takes either 1 or 0. If 1, strict type-checking mode is used for function calls and return statements in the remainder of the file. If 0, weak type-checking mode is used. > > This directive also supports the declare() block syntax (e.g. declare(strict_types=1) { foo(); }), in which case it will only affect function calls and return statements within the block.
-- Andrea Faulds http://ajf.me/

Rasmus Lerdorf

11 years ago
On 02/07/2015 09:51 PM, Andrea Faulds wrote:
>> tan(1); >> echo strstr("test", "est", 1); > > Banning int->float and float->int is both a pain point and sometimes a life-saver. It’s annoying that tan(1) doesn’t work. On the other hand, you discover if your ints floats would be silently truncated (as I did with PictoSwap). > > I wouldn’t say that int->string not working is a problem, though. Seeing something like strstr(“test”, “est”, 1); is rather confusing. Looking at it, I’d think the third parameter is some sort of number for you to want to pass an integer to it. If I want a string, I’ll use one.
This isn't int->string. This is int->boolean. The 3rd arg to strstr() is a boolean and passing 1 instead of true makes it blow up. It is very very common for people to pass 0 or 1 in place of true/false to all sorts of things in PHP.
> Yes, the RFC is somewhat inaccurate in that respect. It is per-file in one sense (like encoding, but unlike ticks, it has no effect on the including or included files). However, it technically affects the remainder of the file, not the whole file.
Well, no, not the remainder of the file either since it can be switched again. It only affects the part of the file between declares if there is a second one. -Rasmus

Pierre Joye

11 years ago
On Feb 8, 2015 10:52 AM, "Rasmus Lerdorf" <rasmus@lerdorf.com> wrote:
> > On 02/07/2015 09:51 PM, Andrea Faulds wrote: > >> tan(1); > >> echo strstr("test", "est", 1); > > > > Banning int->float and float->int is both a pain point and sometimes a
life-saver. It’s annoying that tan(1) doesn’t work. On the other hand, you discover if your ints floats would be silently truncated (as I did with PictoSwap).
> > > > I wouldn’t say that int->string not working is a problem, though.
Seeing something like strstr(“test”, “est”, 1); is rather confusing. Looking at it, I’d think the third parameter is some sort of number for you to want to pass an integer to it. If I want a string, I’ll use one.
> > This isn't int->string. This is int->boolean. The 3rd arg to strstr() is > a boolean and passing 1 instead of true makes it blow up. It is very > very common for people to pass 0 or 1 in place of true/false to all > sorts of things in PHP. > > > Yes, the RFC is somewhat inaccurate in that respect. It is per-file in
one sense (like encoding, but unlike ticks, it has no effect on the including or included files). However, it technically affects the remainder of the file, not the whole file.
> > Well, no, not the remainder of the file either since it can be switched > again. It only affects the part of the file between declares if there is > a second one.
For this specific weirdness it should really be fixed somehow, like for namespace. It has to be used at the top of a file. As it is a compile time thing, the extra check should not have much impact.

Pierre Joye

11 years ago
On Sun, Feb 8, 2015 at 11:33 AM, Pierre Joye <pierre.php@gmail.com> wrote:
>> > Yes, the RFC is somewhat inaccurate in that respect. It is per-file in >> > one sense (like encoding, but unlike ticks, it has no effect on the >> > including or included files). However, it technically affects the remainder >> > of the file, not the whole file. >> >> Well, no, not the remainder of the file either since it can be switched >> again. It only affects the part of the file between declares if there is >> a second one. > > For this specific weirdness it should really be fixed somehow, like for > namespace. It has to be used at the top of a file. As it is a compile time > thing, the extra check should not have much impact.
and it was also not correct that we never used declare for such things. http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_compile.c#3776 about encoding. And it has to get this exact kind of check for the exact same reasons. In other words, we can use the same solution.
-- Pierre @pierrejoye | http://www.libgd.org

Andrew Faulds

11 years ago
Hi,
> On 8 Feb 2015, at 03:52, Rasmus Lerdorf <rasmus@lerdorf.com> wrote: > > On 02/07/2015 09:51 PM, Andrea Faulds wrote: >>> tan(1); >>> echo strstr("test", "est", 1); >> >> Banning int->float and float->int is both a pain point and sometimes a life-saver. It’s annoying that tan(1) doesn’t work. On the other hand, you discover if your ints floats would be silently truncated (as I did with PictoSwap). >> >> I wouldn’t say that int->string not working is a problem, though. Seeing something like strstr(“test”, “est”, 1); is rather confusing. Looking at it, I’d think the third parameter is some sort of number for you to want to pass an integer to it. If I want a string, I’ll use one. > > This isn't int->string. This is int->boolean. The 3rd arg to strstr() is > a boolean and passing 1 instead of true makes it blow up. It is very > very common for people to pass 0 or 1 in place of true/false to all > sorts of things in PHP.
Oh, my bad, I looked up strtr and not strstr. I’m not sure that disallowing implicit integer->boolean conversion is bad, though. That conversion will discard all data except whether the value is non-zero. If you opt in to strict typing, then you have chosen to always use the correct types.
> >> Yes, the RFC is somewhat inaccurate in that respect. It is per-file in one sense (like encoding, but unlike ticks, it has no effect on the including or included files). However, it technically affects the remainder of the file, not the whole file. > > Well, no, not the remainder of the file either since it can be switched > again. It only affects the part of the file between declares if there is > a second one.
Sure, that’s true, the option can be changed more than once.
-- Andrea Faulds http://ajf.me/

Robert Stoll

11 years ago
> -----Ursprüngliche Nachricht----- > Von: Rasmus Lerdorf [mailto:rasmus@lerdorf.com] > Gesendet: Sonntag, 8. Februar 2015 04:53 > An: Andrea Faulds > Cc: Pavel Kouřil; PHP Internals > Betreff: Re: [PHP-DEV] [VOTE] Scalar Type Hints > > On 02/07/2015 09:51 PM, Andrea Faulds wrote: > >> tan(1); > >> echo strstr("test", "est", 1); > > > > Banning int->float and float->int is both a pain point and sometimes a life-saver. It’s annoying that tan(1) doesn’t work. > On the other hand, you discover if your ints floats would be silently truncated (as I did with PictoSwap). > > > > I wouldn’t say that int->string not working is a problem, though. Seeing something like strstr(“test”, “est”, 1); is rather > confusing. Looking at it, I’d think the third parameter is some sort of number for you to want to pass an integer to it. If I > want a string, I’ll use one. > > This isn't int->string. This is int->boolean. The 3rd arg to strstr() is a boolean and passing 1 instead of true makes it blow up. > It is very very common for people to pass 0 or 1 in place of true/false to all sorts of things in PHP. > > > Yes, the RFC is somewhat inaccurate in that respect. It is per-file in one sense (like encoding, but unlike ticks, it has no > effect on the including or included files). However, it technically affects the remainder of the file, not the whole file. > > Well, no, not the remainder of the file either since it can be switched again. It only affects the part of the file between > declares if there is a second one. > > -Rasmus >
I think that it is a perfect example why strict typing has its merits. It is funny to see how confusing it seems to be that you passed 1 instead true but anyway... I already mentioned once that we could handle number literals as different types depending on its context (like Haskell does it). For instance: sin(1) is perfectly fine as well, since 1 is an integer literal and can be used as float literal as well. I would only allow int -> float but not int -> bool (see confusion above). Cheers, Robert

Andi Gutmans

11 years ago
> On Feb 7, 2015, at 7:52 PM, Rasmus Lerdorf <rasmus@lerdorf.com> wrote: > > On 02/07/2015 09:51 PM, Andrea Faulds wrote: >>> tan(1); >>> echo strstr("test", "est", 1); >> >> Banning int->float and float->int is both a pain point and sometimes a life-saver. It’s annoying that tan(1) doesn’t work. On the other hand, you discover if your ints floats would be silently truncated (as I did with PictoSwap). >> >> I wouldn’t say that int->string not working is a problem, though. Seeing something like strstr(“test”, “est”, 1); is rather confusing. Looking at it, I’d think the third parameter is some sort of number for you to want to pass an integer to it. If I want a string, I’ll use one. > > This isn't int->string. This is int->boolean. The 3rd arg to strstr() is > a boolean and passing 1 instead of true makes it blow up. It is very > very common for people to pass 0 or 1 in place of true/false to all > sorts of things in PHP.
Thanks for those relevant examples. I think it’s also worth emphasizing that in C people frequently work around this by forcing casts. The value of strict typing diminishes quickly and the code ends up being less readable. I think in PHP this is going to be even more so due to the reasons Rasmus states. We have *a lot* of places like this which will lead to unnatural acts and code which is no more strict than it was before (just not as pretty). Andi

Nikita Popov

11 years ago
On Sun, Feb 8, 2015 at 3:38 AM, Rasmus Lerdorf <rasmus@lerdorf.com> wrote:
> On 02/07/2015 05:03 PM, Pavel Kouřil wrote: > > I'm wishing more and more that the RFC doesn't pass (even though I'd > > LOVE to have typehints in PHP as a userland developer) and someone > > else will make a better version of typehints RFC for PHP 7, because > > this one feels really like you took an ok-ish RFC (one that would be > > good for PHP) and slapped a strict typing on it without enough > > research about strong typing in other languages. And as I said myself > > multiple times in the past, the declare syntax IS just ugly (and > > changing how code works by writing one line is an ugly principle as > > well, IMHO). :( > > I am not sure I would go that far. Andrea did plenty of research and has > tons of experience in other languages, I just think this approach is > misguided. I also wonder just how many people of those who voted even > bothered to download and try the patch. I tried it a while back on some > existing code and it was a nightmare. Does everyone realize that these > simple things break? > > tan(1); > echo strstr("test", "est", 1); >
Seems like a case where one mans bug is another mans feature. While int->float conversions are debatable (and the answer may not be obvious if you consider bigints) I would definitely want the latter call to error. Seeing strstr("test", "est", 1) I would obviously assume that 1 is an offset parameter, like it is the case with many other str* family functions. strstr("test", "est", true) is a lot more obvious and I'll be happy if PHP yells at me if I'm sacrificing three keystrokes for a lot of readability.
> Basically declare() does not respect function scope, but it doesn't let > you know that. There is a reason we haven't used declare() for anything > real. >
This sounds like a bug more than anything else. It can be easily fixed. Nikita

Stas Malyshev

11 years ago
Hi!
> * Requiring an exact type match has the least mental overhead, and > allows types to be checked at compile-time
What compile-time you're talking about? PHP has no "compile time".
-- Stas Malyshev smalyshev@gmail.com

Sanford Whiteman

11 years ago
> ...cases that make sense to nearly everybody for abstract bondage-and-discipline notion 
Well, the 50 Shades of Grey movie is coming out soon, so let's wait and see how that does. :)

Umberto Salsi

11 years ago
ajf@ajf.me (Andrea Faulds) wrote:
> * Always allowing implicit conversions from int to float is sometimes > going to cause data loss, so it may also be reasonable for PHP to > prevent this specific case
IMHO, automatic conversion int --> float is perfectly reasonable because: 1) int can always be converted to float, possibly loosing some less significant digists (int on 64-bit PCs can contain up to 19 digits, float contains up to about 16 digits); 2) the called function is already aware (according to the contract of its interface accepting float) that the passed value is an "approximated representation of a number", and should also be aware of all the limitations of the floating-point arithmetic.
> * Requiring an exact type match has the least mental overhead, and > allows types to be checked at compile-time
Agree with the first part of the sentence (saving neural cells, specially when you have to understand someone else's code...), but there is no need for a "compiler" to garantee the type-safety of a program: static validation can be used right now on PHP using DocBlocks only, without the need to add new features or to change the current syntax of the language. For example: /** * @param float $x * @param float $y * @return float */ function modulus($x, $y) { return sqrt($x*$x + $y*$y); } echo modulus(1,1); can be easily statically validated and is perfectly equivalent to the possible new syntax: function modulus(float $x, float $y): float { return sqrt($x*$x + $y*$y); } echo modulus(1,1); Rather than changing PHP trying to (badly) imitate other languages, the language might evolve in another completely different direction preserving its nature of scripting language, but paying more attention designing its features (syntax, libraries, etc.) so that static validation and eventually compilation into an efficient binary executable code can be performed. Regards, ___ /_|_\ Umberto Salsi \/_\/ www.icosaedro.it

Stas Malyshev

11 years ago
Hi!
> I don’t think it’s unfair. There’s a limited set of permitted > conversions in some strictly-typed languages, but it’s still > strictly-typed.
The main problem with strict typing as it is being proposed by strictness proponents is exactly that - there's no limited set permitted. It leads to absurd limitations like 1 not accepted where a float value is required, or where a boolean value is required. That's the essential problem with this proposal - it sacrifices the frequent use cases that make sense to nearly everybody for abstract bondage-and-discipline notion under misguided assumption that it would be a service to the users. In fact, if forced to use this API, people would probably just learn to do (float) each time they call such function, which makes them just do more work for something they could have - and already do have, in internal functions - for free.
-- Stas Malyshev smalyshev@gmail.com

Andrew Faulds

11 years ago
Hi, I’m posting this in a new thread since people might (reasonably) be ignoring further responses to the [VOTE] thread. I’m considering a small change to the Scalar Type Hints RFC, specifically about syntax. Quite a few people have said they don’t like the declare() syntax, and it’s easy to see why. It’s rather verbose, it has all the quirks of declare() (such as block syntax, not respecting scope), and it’s rather ugly. Instead, I’m wondering if the following might be better: <?php strict Which would be used like so: <?php strict function foobar(): int { return 1.0; // error! } It’d be a per-file directive, so there’d be zero mixing of modes within one file, and you’d avoid the quirks of declare(). It’s also a lot shorter, and it resembles Hack’s syntax: <?hh // strict Of course, changing this would mean restarting the vote, but it’s only been three days, we’re less than a quarter of the way through voting. Thoughts? Thanks! (By the way, I’d appreciate it if this thread didn’t turn into yet another discussion of how and whether scalar type hints are a bad/good idea. We already have at least four threads on that subject. I’m just considering a specific change of syntax.)
-- Andrea Faulds http://ajf.me/

Zeev Suraski

11 years ago
FWIW, while I think strict types - stricter than even strict languages - don't belong in PHP, this syntax is clearly a step up from declare(), which was definitely not intended for this purpose. Zeev

Rowan Collins

11 years ago
On 08/02/2015 20:33, Zeev Suraski wrote:
> FWIW, while I think strict types - stricter than even strict languages - > don't belong in PHP, this syntax is clearly a step up from declare(), which > was definitely not intended for this purpose.
I'm kind of intrigued what purpose it *was* intended for. I've always found it a rather odd part of the language, but this seems as logical a use for it as any. For years, it had exactly one "execution directive", which worked in concert with a runtime event handler (ticks=N + register_tick_function). In PHP 5.3, a completely unrelated directive was added, to specify the encoding of the file (something that more obviously has to be detected by the compiler). Was there an original idea of what it would be used for that never came to fruition? Or is there something I'm missing that connects "ticks" and "encoding", but excludes "strict_types"? Regards,
-- Rowan Collins [IMSoP]

Pierre Joye

11 years ago
On Mon, Feb 9, 2015 at 6:30 AM, Rowan Collins <rowan.collins@gmail.com> wrote:
> On 08/02/2015 20:33, Zeev Suraski wrote: >> >> FWIW, while I think strict types - stricter than even strict languages - >> don't belong in PHP, this syntax is clearly a step up from declare(), >> which >> was definitely not intended for this purpose. > > > I'm kind of intrigued what purpose it *was* intended for. I've always found > it a rather odd part of the language, but this seems as logical a use for it > as any. > > For years, it had exactly one "execution directive", which worked in concert > with a runtime event handler (ticks=N + register_tick_function). In PHP 5.3, > a completely unrelated directive was added, to specify the encoding of the > file (something that more obviously has to be detected by the compiler). > > Was there an original idea of what it would be used for that never came to > fruition? Or is there something I'm missing that connects "ticks" and > "encoding", but excludes "strict_types"?
Both are being done at compile time and modify how a file is compiled. So no, I do not agree with "runtime" here, while one directive is being used at runtime.
-- Pierre @pierrejoye | http://www.libgd.org

Rowan Collins

11 years ago
Pierre Joye wrote on 09/02/2015 00:05:
> On Mon, Feb 9, 2015 at 6:30 AM, Rowan Collins <rowan.collins@gmail.com> wrote: >> On 08/02/2015 20:33, Zeev Suraski wrote: >>> FWIW, while I think strict types - stricter than even strict languages - >>> don't belong in PHP, this syntax is clearly a step up from declare(), >>> which >>> was definitely not intended for this purpose. >> >> I'm kind of intrigued what purpose it *was* intended for. I've always found >> it a rather odd part of the language, but this seems as logical a use for it >> as any. >> >> For years, it had exactly one "execution directive", which worked in concert >> with a runtime event handler (ticks=N + register_tick_function). In PHP 5.3, >> a completely unrelated directive was added, to specify the encoding of the >> file (something that more obviously has to be detected by the compiler). >> >> Was there an original idea of what it would be used for that never came to >> fruition? Or is there something I'm missing that connects "ticks" and >> "encoding", but excludes "strict_types"? > Both are being done at compile time and modify how a file is compiled. > So no, I do not agree with "runtime" here, while one directive is > being used at runtime.
I didn't say it was runtime, I said it "worked in concert with" runtime code. My point was that declare(encoding) is something purely internal to the compiler, affecting how it parses the file, whereas declare(ticks) is using the compiler to change the actual execution of the code, which makes them feel very different in effect. It's quite hard to generalise from those two examples to any real "vision" of declare()'s purpose, so I was genuinely curious what that vision was. Regards,
-- Rowan Collins [IMSoP]

Pierre Joye

11 years ago
On Mon, Feb 9, 2015 at 3:33 AM, Zeev Suraski <zeev@zend.com> wrote:
> FWIW, while I think strict types - stricter than even strict languages - > don't belong in PHP, this syntax is clearly a step up from declare(), which > was definitely not intended for this purpose.
I think we get it, you do not like the ground idea behind this RFC. There is no need to repeat the same arguement again and again.

François Laupretre

11 years ago
> De : Andrea Faulds [mailto:ajf@ajf.me] > Instead, I’m wondering if the following might be better: > > <?php strict > > Which would be used like so: > > <?php strict > > function foobar(): int { > return 1.0; // error! > } > > It’d be a per-file directive, so there’d be zero mixing of modes within one > file, and you’d avoid the quirks of declare().
'<?php' is not a 'per-file' directive, as it can appear several times, and is not always the first item in a file. What would this mean : Lines of data ... <?php php code ?> Data <?php strict Code ... Would it be strict or not ? or will you interpret the first '<?php' only ? What is the syntax exactly ? Does it make 'strict' a reserved keyword ? I am sorry but, IMO, it adds ambiguity to declare()'s ugliness. François

Andrew Faulds

11 years ago
Hi François, On 8 Feb 2015, at 20:43, François Laupretre <francois@tekwire.net> wrote:
>> De : Andrea Faulds [mailto:ajf@ajf.me] >> Instead, I’m wondering if the following might be better: >> >> <?php strict >> >> Which would be used like so: >> >> <?php strict >> >> function foobar(): int { >> return 1.0; // error! >> } >> >> It’d be a per-file directive, so there’d be zero mixing of modes within one >> file, and you’d avoid the quirks of declare(). > > '<?php' is not a 'per-file' directive, as it can appear several times, and is not always the first item in a file. > > What would this mean : > > Lines of data > ... > <?php > php code > ?> > Data > <?php strict > Code > ... > > Would it be strict or not ? or will you interpret the first '<?php' only ? What is the syntax exactly ? Does it make 'strict' a reserved keyword ?
It doesn't make "strict" be reserved. With regards to multiple blocks, there are a few possible approaches: * First block affects subsequent blocks, only it can declare strictness (my favourite) * Per-block * Use of directive prevents use of end tags, and thus use of multiple blocks I think the first makes the most sense. It's what namespaces do, after all. Thanks.
-- Andrea Faulds http://ajf.me/

Rowan Collins

11 years ago
On 08/02/2015 19:44, Andrea Faulds wrote:
> Hi, > > I’m posting this in a new thread since people might (reasonably) be ignoring further responses to the [VOTE] thread.
Incidentally, you still used "reply" to create this message, so mail readers which base threads on headers (e.g. Thunderbird) rather than subject lines (e.g. GMail) still see it as part of the same thread (though the subject line change makes it stand out, so I spotted it anyway).
> I’m considering a small change to the Scalar Type Hints RFC, specifically about syntax. Quite a few people have said they don’t like the declare() syntax, and it’s easy to see why. It’s rather verbose, it has all the quirks of declare() (such as block syntax, not respecting scope), and it’s rather ugly. > > Instead, I’m wondering if the following might be better: > > <?php strict > > Which would be used like so: > > <?php strict > > function foobar(): int { > return 1.0; // error! > } > > It’d be a per-file directive, so there’d be zero mixing of modes within one file, and you’d avoid the quirks of declare().
I find this much, much uglier than declare(). Firstly, it seems to be creating a whole new syntax convention, which will need its own rules - Can it be preceded by a newline or other whitespace? Must it be followed by a newline (unlike a normal "<?php" opening)? Could you enable strict typing in a short tag using "<?= strict some_function($bar); ?>"? Secondly, it is less specific than the current proposal - it suggests that PHP has a generic "strict mode", rather than a "strict type-checking" mode. Would more "strict" features be added to this mode later? Or would other keywords be added so that you could, ahem, "declare" several directives at the top of your block? Thirdly, it has all the same scoping issues as declare() - you can break a function up into multiple <?php ... ?> blocks, so it's still possible to switch it halfway through a declaration, unless extra rules are added. But it's worse than that, because you could start halfway through one function, and end halfway through the next: <?php function foo() { // non strict code ?><?php strict // strict code } function bar() { // still strict ?><?php // not strict } That's impossible with the block version of declare(), because it uses the same block syntax of { and } as the rest of the code. It might be possible with the non-block declare(), but it would make more sense to simply fix that than to introduce a whole new piece of syntax. If this magic token has the extra effect of causing ?> to be ignored, that's a fairly major and unrelated feature, which would probably need its own RFC. If you make the first "<?php" in a file special, that's still something that was never a consideration before. It's not like non-block namespace declarations having to be at the top of the file, because that is still a separate statement, it just has to be the *first* statement; whereas this appears to be designed to merge with the non-statement opening tag. If you're going to go that far, why not just disallow the block-level syntax of declare() for this case, if that is the complaint? Or if the problem is the non-block syntax, why not enforce that a non-block declare(strict_types) be at the top of the file? I'm not really sure what problem you're trying to solve, but this to me looks like a piece of magic that doesn't resemble anything else in PHP. Regards,
-- Rowan Collins [IMSoP]

Andrew Faulds

11 years ago
Hi,
> On 8 Feb 2015, at 23:22, Rowan Collins <rowan.collins@gmail.com> wrote: > > On 08/02/2015 19:44, Andrea Faulds wrote: >> Hi, >> >> I’m posting this in a new thread since people might (reasonably) be ignoring further responses to the [VOTE] thread. > > Incidentally, you still used "reply" to create this message, so mail readers which base threads on headers (e.g. Thunderbird) rather than subject lines (e.g. GMail) still see it as part of the same thread (though the subject line change makes it stand out, so I spotted it anyway).
Oh yeah, my bad. :/
> >> I’m considering a small change to the Scalar Type Hints RFC, specifically about syntax. Quite a few people have said they don’t like the declare() syntax, and it’s easy to see why. It’s rather verbose, it has all the quirks of declare() (such as block syntax, not respecting scope), and it’s rather ugly. >> >> Instead, I’m wondering if the following might be better: >> >> <?php strict >> >> Which would be used like so: >> >> <?php strict >> >> function foobar(): int { >> return 1.0; // error! >> } >> >> It’d be a per-file directive, so there’d be zero mixing of modes within one file, and you’d avoid the quirks of declare(). > > I find this much, much uglier than declare(). > > Firstly, it seems to be creating a whole new syntax convention, which will need its own rules - Can it be preceded by a newline or other whitespace? Must it be followed by a newline (unlike a normal "<?php" opening)? Could you enable strict typing in a short tag using "<?= strict some_function($bar); ?>”?
<?php strict is allowed <?php strict is not. It would not be supported for <?=. It would be supported for <?. I guess it would have to be followed by a new line.
> Secondly, it is less specific than the current proposal - it suggests that PHP has a generic "strict mode", rather than a "strict type-checking" mode.
It could be renamed to strict_types, but that loses some elegant.
> Would more "strict" features be added to this mode later?
No.
> Or would other keywords be added so that you could, ahem, "declare" several directives at the top of your block?
No.
> Thirdly, it has all the same scoping issues as declare() - you can break a function up into multiple <?php ... ?> blocks, so it's still possible to switch it halfway through a declaration,
I’ve already sent an email in this thread about possible approaches to handling multiple blocks. My preferred solution would not allow what you describe, and instead behave like namespaces (must be in first block, affects entire file).
> If this magic token has the extra effect of causing ?> to be ignored, that's a fairly major and unrelated feature, which would probably need its own RFC.
?> isn’t ignored - PHP blocks aren’t, and never have, been considered the same as separate files.
> If you make the first "<?php" in a file special, that's still something that was never a consideration before.
This is technically correct, but only if that first block is empty. The following is an error: <?php ?> Test <?php namespace foo; Though this isn’t: <?php ?> <?php namespace foo;
> It's not like non-block namespace declarations having to be at the top of the file, because that is still a separate statement, it just has to be the *first* statement; whereas this appears to be designed to merge with the non-statement opening tag.
Is there really an important difference between first statement, and first opening tag? The main difference in behaviour is empty blocks.
> If you're going to go that far, why not just disallow the block-level syntax of declare() for this case, if that is the complaint? Or if the problem is the non-block syntax, why not enforce that a non-block declare(strict_types) be at the top of the file?
Well, it’s not just that which is the problem: declare() is rather verbose and ugly. Also, having it behave differently from all other declare() statements would bring into question why we even bother reusing the declare() syntax.
-- Andrea Faulds http://ajf.me/

Rowan Collins

11 years ago
On 09/02/2015 00:05, Andrea Faulds wrote:
>> Secondly, it is less specific than the current proposal - it suggests that PHP has a generic "strict mode", rather than a "strict type-checking" mode. > It could be renamed to strict_types, but that loses some elegant. > >> Would more "strict" features be added to this mode later? > No. > >> Or would other keywords be added so that you could, ahem, "declare" several directives at the top of your block? > No.
I think this is all rather optimistic - if you use a specific term like "strict_types", people will want to use this syntax for other keywords; if you use something as general as "strict", they will want to add additional semantics to the existing keyword.
>> Thirdly, it has all the same scoping issues as declare() - you can break a function up into multiple <?php ... ?> blocks, so it's still possible to switch it halfway through a declaration, > I’ve already sent an email in this thread about possible approaches to handling multiple blocks. My preferred solution would not allow what you describe, and instead behave like namespaces (must be in first block, affects entire file). > >> If this magic token has the extra effect of causing ?> to be ignored, that's a fairly major and unrelated feature, which would probably need its own RFC. > ?> isn’t ignored - PHP blocks aren’t, and never have, been considered the same as separate files.
This was in response to your suggestion in the other message that that was a possible (though not your preferred) way to deal with the scoping issue. I edited my post for brevity, and didn't make the reference clear.
> >> It's not like non-block namespace declarations having to be at the top of the file, because that is still a separate statement, it just has to be the *first* statement; whereas this appears to be designed to merge with the non-statement opening tag. > Is there really an important difference between first statement, and first opening tag? The main difference in behaviour is empty blocks.
I guess it's more that statements, wherever they appear, are a recognisable part of the language. Tokens sharing a line with the opening tag aren't, and I don't see why this feature is so special that it requires the creation of a whole new syntax feature.
>> If you're going to go that far, why not just disallow the block-level syntax of declare() for this case, if that is the complaint? Or if the problem is the non-block syntax, why not enforce that a non-block declare(strict_types) be at the top of the file? > Well, it’s not just that which is the problem: declare() is rather verbose and ugly. Also, having it behave differently from all other declare() statements would bring into question why we even bother reusing the declare() syntax.
I'd rather verbose and clear than concise and vague. Regards,
-- Rowan Collins [IMSoP]

François Laupretre

11 years ago
> De : Rowan Collins [mailto:rowan.collins@gmail.com] > > >> Would more "strict" features be added to this mode later? > > No. > > > >> Or would other keywords be added so that you could, ahem, "declare" > several directives at the top of your block? > > No. > > I think this is all rather optimistic - if you use a specific term like > "strict_types", people will want to use this syntax for other keywords; > if you use something as general as "strict", they will want to add > additional semantics to the existing keyword.
+1. We cannot allow a keyword (yes, it IS a reserved keyword) in this location and say "Oh, that's just an exception for strict type checking, but no one has the right to do the same, except Andrea if she needs it again in the future.". If we extend the syntax, we must establish rules for keywords on the same line as '<?php'. IMO, it would apply to the code block, not to the whole file, or you need to add constraints that go too far (disable '?>' and the like). Unfortunately, the BC break would probably make such an RFC still more problematic than strict typing. Another concern is that 'strict', while elegant, is ambiguous. I guess most people would think it enables E_STRICT, which I would intuitively believe. Cheers François

Rowan Collins

11 years ago
Andrea Faulds wrote on 09/02/2015 00:05:
>> If you're going to go that far, why not just disallow the block-level syntax of declare() for this case, if that is the complaint? Or if the problem is the non-block syntax, why not enforce that a non-block declare(strict_types) be at the top of the file? > Well, it’s not just that which is the problem: declare() is rather verbose and ugly. Also, having it behave differently from all other declare() statements would bring into question why we even bother reusing the declare() syntax.
Thinking about it, declare(encoding) already disallows scope anyway, so we wouldn't even be introducing something new: "Fatal error: Encoding declaration pragma must be the very first statement in the script".

Pierre Joye

11 years ago
hi, On Mon, Feb 9, 2015 at 2:44 AM, Andrea Faulds <ajf@ajf.me> wrote:
> Hi, > > I’m posting this in a new thread since people might (reasonably) be ignoring further responses to the [VOTE] thread. > > I’m considering a small change to the Scalar Type Hints RFC, specifically about syntax. Quite a few people have said they don’t like the declare() syntax, and it’s easy to see why. It’s rather verbose, it has all the quirks of declare() (such as block syntax, not respecting scope), and it’s rather ugly. > > Instead, I’m wondering if the following might be better: > > <?php strict > > Which would be used like so: > > <?php strict > > function foobar(): int { > return 1.0; // error! > } > > It’d be a per-file directive, so there’d be zero mixing of modes within one file, and you’d avoid the quirks of declare(). > > It’s also a lot shorter, and it resembles Hack’s syntax: > > <?hh // strict > > Of course, changing this would mean restarting the vote, but it’s only been three days, we’re less than a quarter of the way through voting. > > Thoughts? Thanks! > > (By the way, I’d appreciate it if this thread didn’t turn into yet another discussion of how and whether scalar type hints are a bad/good idea. We already have at least four threads on that subject. I’m just considering a specific change of syntax.) >
I am not sure I like this. It is somehow not very phpish :) May I ask why you like to do it? Declare works well and only need a couple of line to make it work like encoding. We may fix as well other related issues, nothing that does not look fixable. Cheers,
-- Pierre @pierrejoye | http://www.libgd.org

Ferenc Kovacs

11 years ago
On Thu, Feb 5, 2015 at 9:14 PM, Andrea Faulds <ajf@ajf.me> wrote:
> Good evening, > > At long last, I’m going to put the RFC to a vote. It’s been long enough - > I don’t think there needs to be, or will be, much further discussion. > > I’d like to make sure that everyone voting understands the RFC fully. > Please read the RFC in full: the details are important. And if anyone has > any questions or uncertainties, please ask them before voting. I am very > happy to answer them. > > I would urge everyone who wants type hints to vote for this RFC. It is not > a perfect solution, but there can be no perfect solution to this issue. > However, I think it is better than most of the alternatives suggested thus > far - see the rationale section, and previous discussions. Crucially, this > RFC would keep PHP a weakly-typed language, and not force either strict > typing, nor weak typing, on anyone who does not want it. It would allow the > addition of type hints to existing codebases. It would not create a > situation where userland functions are strict yet internal functions are > not, because the strict mode affects both. I’ve tested the implementation > myself on my own code, and it worked well, providing benefits other > proposals would not have given (see my previous post about my experiences). > > Voting starts today (2015-02-05) and ends in two weeks’ time (2015-02-19). > In addition to the vote on the main RFC, there is also a vote on the type > aliases issue, and a vote to reserve the type names for future RFCs’ sake > if this RFC fails. > > The RFC can be found here, and it contains a voting widget: > https://wiki.php.net/rfc/scalar_type_hints > > Thank you for your time. > > -- > Andrea Faulds > http://ajf.me/ > > > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >
hi, I've voted no for two reasons: 1, I don't really like the the proposed declare solution, I know that you put much thought and effort with finding a way to make the strict hints opt-in for the caller, but I think it is still not a good compromise: people in favor of strict hints will hate it because it is opt-in from the caller, so they can't use scalar hints to save the boilerplate for argument validation, and other people like me will unlike it because they think that the blockless declare will cause many errors and debugging headache when somebody moves some code between files (or concatenating files as part of their deployment process). 2, As this is a really polarizing topic I would like if the eventual solution would have wider support from the current php-src regular contributors, and not just pushed through by "force". (And I know that status quo sucks when somebody trying to do innovative stuff, but it is a safe thing to default to). Thanks for your efforts on such a hard topic and I hope you can eventually succeed where everyone else failed thus far!
-- Ferenc Kovács @Tyr43l - http://tyrael.hu

Andrew Faulds

11 years ago
Hi Ferenc,
> On 8 Feb 2015, at 22:18, Ferenc Kovacs <tyra3l@gmail.com> wrote: > > I've voted no for two reasons: > 1, I don't really like the the proposed declare solution, I know that you put much thought and effort with finding a way to make the strict hints opt-in for the caller, but I think it is still not a good compromise: people in favor of strict hints will hate it because it is opt-in from the caller, so they can't use scalar hints to save the boilerplate for argument validation
Hmm. Personally, I don’t think types are really a substitute for argument validation. This doesn’t provide a means to force strict types upon people who don’t want them, sure… but the proposal is designed precisely to prevent that, since I don’t see someone like Zeev (say) wanting to deal with strict types any time soon.
> , and other people like me will unlike it because they think that the blockless declare will cause many errors and debugging headache when somebody moves some code between files (or concatenating files as part of their deployment process).
It’s worth noting that I intend to change this to have the “<?php strict” syntax rather than declare(). That’ll have to be a subsequent RFC, as I don’t want to cancel the vote. But it looks like it will pass since all the feedback I’ve got about that so far has been positive.
> 2, As this is a really polarizing topic I would like if the eventual solution would have wider support from the current php-src regular contributors, and not just pushed through by "force". (And I know that status quo sucks when somebody trying to do innovative stuff, but it is a safe thing to default to).
I’m not sure. There are some people completely opposed to compromise, that can’t be helped. For everyone else, I’m not sure how I feel about contentious votes. If it gets through by a 2/3 majority then presumably it does have significant support, though I worry about lasting impact. Votes do, at least, provide a way to resolve contentious issues, though.
> Thanks for your efforts on such a hard topic and I hope you can eventually succeed where everyone else failed thus far!
Thanks.
-- Andrea Faulds http://ajf.me/

Ivan Enderlin @ Hoa

11 years ago
Hello internal, Thank you Andrea for this RFC. I voted today. However, I would like to stress that my vote represents the opinion of Hoa's community [1] and fruux [2] (the company behind sabre/dav [3]). I talked to Pierre Joye today and I was mentioning this is something we do since few months already and I had to spread the word here. So yes, my vote does not represent only 1 person but tens. This is something we will continue since we believe that a vote must not represent the opinion of one person. We consider this is an opportunity to fill the gap between internal and PHP's community. And finally, we would like to encourage people with a vote to talk to anybody around them, at their work, at their open-source project, on IRC etc. to reflect the most valuable opinion. Cheers :-). [1] http://hoa-project.net/ [2] https://fruux.com/ [3] http://sabre.io/ On 05/02/15 21:14, Andrea Faulds wrote:

Pascal MARTIN

11 years ago
Le 05/02/2015 21:14, Andrea Faulds a écrit :
> At long last, I’m going to put the RFC to a vote. It’s been long enough - I don’t think there needs to be, or will be, much further discussion. > > I’d like to make sure that everyone voting understands the RFC fully. Please read the RFC in full: the details are important. And if anyone has any questions or uncertainties, please ask them before voting. I am very happy to answer them. > > I would urge everyone who wants type hints to vote for this RFC. It is not a perfect solution, but there can be no perfect solution to this issue. However, I think it is better than most of the alternatives suggested thus far - see the rationale section, and previous discussions. Crucially, this RFC would keep PHP a weakly-typed language, and not force either strict typing, nor weak typing, on anyone who does not want it. It would allow the addition of type hints to existing codebases. It would not create a situation where userland functions are strict yet internal functions are not, because the strict mode affects both. I’ve tested the implementation myself on my own code, and it worked well, providing benefits other proposals would not have given (see my previous post about my experiences). >
Hi, Just to let you know, I've written a post about this RFC on my blog, trying to present what it brings to the table and to explain why I like it: http://blog.pascal-martin.fr/post/in-favor-of-rfc-scalar-type-hints.html Maybe another way of presenting things might help some people here to decide whether or not they think this RFC is helpful. Even if I've published this earlier today, I've written it between Thursday and Friday, so it doesn't really take into account the new ideas (new syntax propositions) that have been posted since. Please note this is *my* personal opinion, and doesn't necessarily reflect the opinion of any organization I am affiliated with. Pascal.
-- Pascal MARTIN http://blog.pascal-martin.fr @pascal_martin

Laruence

11 years ago
Hey: On Fri, Feb 6, 2015 at 4:14 AM, Andrea Faulds <ajf@ajf.me> wrote:
> Good evening, > > At long last, I’m going to put the RFC to a vote. It’s been long enough - I don’t think there needs to be, or will be, much further discussion. > > I’d like to make sure that everyone voting understands the RFC fully. Please read the RFC in full: the details are important. And if anyone has any questions or uncertainties, please ask them before voting. I am very happy to answer them. > > I would urge everyone who wants type hints to vote for this RFC. It is not a perfect solution, but there can be no perfect solution to this issue. However, I think it is better than most of the alternatives suggested thus far - see the rationale section, and previous discussions. Crucially, this RFC would keep PHP a weakly-typed language, and not force either strict typing, nor weak typing, on anyone who does not want it. It would allow the addition of type hints to existing codebases. It would not create a situation where userland functions are strict yet internal functions are not, because the strict mode affects both. I’ve tested the implementation myself on my own code, and it worked well, providing benefits other proposals would not have given (see my previous post about my experiences). > > Voting starts today (2015-02-05) and ends in two weeks’ time (2015-02-19). In addition to the vote on the main RFC, there is also a vote on the type aliases issue, and a vote to reserve the type names for future RFCs’ sake if this RFC fails. > > The RFC can be found here, and it contains a voting widget: https://wiki.php.net/rfc/scalar_type_hints > > Thank you for your time. >
Actually, I was surprised by the progress of voting now... Seems never have so many users to vote... and bulk of active core developers are vote against on it. As a PHP user, I actually don't care about scalar type hinting much.. but I am strongly objecting declare thing... image of, one line setting care make a project doesn't work... image of, a larger project, some devers user strict_type, some for safe doesn't use.. then they have to add declare to every files's head... it's a nightmare.... I , here, acking you please reconsidering your vote... thanks
> -- > Andrea Faulds > http://ajf.me/ > > > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >
-- Xinchen Hui @Laruence http://www.laruence.com/

Laruence

11 years ago
Hey: On Wed, Feb 11, 2015 at 11:36 AM, Xinchen Hui <laruence@php.net> wrote:
> Hey: > > > On Fri, Feb 6, 2015 at 4:14 AM, Andrea Faulds <ajf@ajf.me> wrote: >> Good evening, >> >> At long last, I’m going to put the RFC to a vote. It’s been long enough - I don’t think there needs to be, or will be, much further discussion. >> >> I’d like to make sure that everyone voting understands the RFC fully. Please read the RFC in full: the details are important. And if anyone has any questions or uncertainties, please ask them before voting. I am very happy to answer them. >> >> I would urge everyone who wants type hints to vote for this RFC. It is not a perfect solution, but there can be no perfect solution to this issue. However, I think it is better than most of the alternatives suggested thus far - see the rationale section, and previous discussions. Crucially, this RFC would keep PHP a weakly-typed language, and not force either strict typing, nor weak typing, on anyone who does not want it. It would allow the addition of type hints to existing codebases. It would not create a situation where userland functions are strict yet internal functions are not, because the strict mode affects both. I’ve tested the implementation myself on my own code, and it worked well, providing benefits other proposals would not have given (see my previous post about my experiences). >> >> Voting starts today (2015-02-05) and ends in two weeks’ time (2015-02-19). In addition to the vote on the main RFC, there is also a vote on the type aliases issue, and a vote to reserve the type names for future RFCs’ sake if this RFC fails. >> >> The RFC can be found here, and it contains a voting widget: https://wiki.php.net/rfc/scalar_type_hints >> >> Thank you for your time. >> > Actually, I was surprised by the progress of voting now... > > Seems never have so many users to vote... and bulk of active core > developers are vote against on it. > > As a PHP user, I actually don't care about scalar type hinting much.. > > but I am strongly objecting declare thing... > > image of, one line setting care make a project doesn't work... > > image of, a larger project, some devers user strict_type, some for > safe doesn't use.. > > then they have to add declare to every files's head... > > it's a nightmare.... > > I , here, acking you please reconsidering your vote...
<?php include_one "lib/xxxx.php" // it use strict type declare(strict_types=0); //damned , restore it. $a = new B; // autoload, target file use strict type, declare(strict_types = 0); //damned, restore it. ?> am I wrong?! thanks
> > thanks >> -- >> Andrea Faulds >> http://ajf.me/ >> >> >> >> >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> > > > > -- > Xinchen Hui > @Laruence > http://www.laruence.com/
-- Xinchen Hui @Laruence http://www.laruence.com/

Laruence

11 years ago
Hey: On Wed, Feb 11, 2015 at 11:45 AM, Xinchen Hui <laruence@php.net> wrote:
> Hey: > > On Wed, Feb 11, 2015 at 11:36 AM, Xinchen Hui <laruence@php.net> wrote: >> Hey: >> >> >> On Fri, Feb 6, 2015 at 4:14 AM, Andrea Faulds <ajf@ajf.me> wrote: >>> Good evening, >>> >>> At long last, I’m going to put the RFC to a vote. It’s been long enough - I don’t think there needs to be, or will be, much further discussion. >>> >>> I’d like to make sure that everyone voting understands the RFC fully. Please read the RFC in full: the details are important. And if anyone has any questions or uncertainties, please ask them before voting. I am very happy to answer them. >>> >>> I would urge everyone who wants type hints to vote for this RFC. It is not a perfect solution, but there can be no perfect solution to this issue. However, I think it is better than most of the alternatives suggested thus far - see the rationale section, and previous discussions. Crucially, this RFC would keep PHP a weakly-typed language, and not force either strict typing, nor weak typing, on anyone who does not want it. It would allow the addition of type hints to existing codebases. It would not create a situation where userland functions are strict yet internal functions are not, because the strict mode affects both. I’ve tested the implementation myself on my own code, and it worked well, providing benefits other proposals would not have given (see my previous post about my experiences). >>> >>> Voting starts today (2015-02-05) and ends in two weeks’ time (2015-02-19). In addition to the vote on the main RFC, there is also a vote on the type aliases issue, and a vote to reserve the type names for future RFCs’ sake if this RFC fails. >>> >>> The RFC can be found here, and it contains a voting widget: https://wiki.php.net/rfc/scalar_type_hints >>> >>> Thank you for your time. >>> >> Actually, I was surprised by the progress of voting now... >> >> Seems never have so many users to vote... and bulk of active core >> developers are vote against on it. >> >> As a PHP user, I actually don't care about scalar type hinting much.. >> >> but I am strongly objecting declare thing... >> >> image of, one line setting care make a project doesn't work... >> >> image of, a larger project, some devers user strict_type, some for >> safe doesn't use.. >> >> then they have to add declare to every files's head... >> >> it's a nightmare.... >> >> I , here, acking you please reconsidering your vote... > > <?php > > include_one "lib/xxxx.php" // it use strict type > > declare(strict_types=0); //damned , restore it. > > > $a = new B; // autoload, target file use strict type, > > declare(strict_types = 0); //damned, restore it. > > > ?> > > am I wrong?!
seems I am wrong with this, it's a false alarm... it can restore automatically. ignore me.. :< thanks
> > thanks >> >> thanks >>> -- >>> Andrea Faulds >>> http://ajf.me/ >>> >>> >>> >>> >>> >>> -- >>> PHP Internals - PHP Runtime Development Mailing List >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >> >> >> >> -- >> Xinchen Hui >> @Laruence >> http://www.laruence.com/ > > > > -- > Xinchen Hui > @Laruence > http://www.laruence.com/
-- Xinchen Hui @Laruence http://www.laruence.com/

Rasmus Lerdorf

11 years ago
On 02/10/2015 07:57 PM, Xinchen Hui wrote:
>> am I wrong?! > seems I am wrong with this, it's a false alarm... it can restore automatically.
Yeah, declare() doesn't span files so that isn't a problem. My worry is still the lack of type coercion for internal calls. I tested it on some apps and it will take quite a bit of tedious and rather useless effort to fix these to run in strict mode. Some examples of common things that are fatal errors in strict mode: ini_set('precision', 14); ini_set('display_errors', 1); ini_set('display_errors', true); ok, not common, but tan(4/2) fatal, tan(5/2) no error Wordpress has this function, spot the error: function add_magic_quotes( $array ) { foreach ( (array) $array as $k => $v ) { if ( is_array( $v ) ) { $array[$k] = add_magic_quotes( $v ); } else { $array[$k] = addslashes( $v ); } } return $array; } $v may not always be a string (it died with a float for me), so the fix is to cast: $array[$k] = addslashes( (string)$v ); Also from Wordpress: $formatted = number_format( $number, absint( $decimals ), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] ); Here number_format() is expecting a float but $number is a string. So again, the only real fix is to cast. And in Drupal8 *without turning on strict*: use Drupal\Component\Utility\String; it dies with: "Fatal error: "string" cannot be used as a class name in /var/www/drupal/core/includes/bootstrap.inc on line 11" That String class is everywhere in Drupal. They are going to have a fun time with that. See https://gist.githubusercontent.com/anonymous/d9252deeeb2aae1a5af5/raw/053155130d22551b1404d0a9b94e27424544b6d1/gistfile1 From Geeklog: if (strtolower($topic) != strtolower($archivetid)) { $sql .= " AND ta.tid != '{$archivetid}' "; } $topic can be null there. Looking at the logic, not really a bug, just a natural reliance on null being coerced to "" Also from Geeklog: if( empty( $date )) { // Date is empty, get current date/time $stamp = time(); } else if( is_numeric( $date )) { // This is a timestamp $stamp = $date; } else { // This is a string representation of a date/time $stamp = strtotime( $date ); } // Format the date $date = strftime( $dateformat, $stamp ); strftime() expects an integer for the timestamp there, but as the above logic shows, they are expecting a numeric string to be fine. No bug, just another forced cast. And another number_format() instance where arg1 is not necessarily a float. Obviously not a bug, so we have to cast again: return number_format( $number, $dc, $ds, $ts ); In Opencart: $this->image = imagecreatetruecolor($width, $height); imagecreatetruecolor() expects parameter 1 to be integer, string given in /var/www/opencart/system/library/image.php on line 89 You could argue this is a bug, I guess, but the width and height are coming from a database and are integers in the db, but since the db returns strings. Another cast... I was genuinely hoping to find some bugs with this exercise. I suppose it is because I did it on mature projects and at this stage those sorts of bugs have already been fixed. But I still fear that people are going to want to be enable strictness everywhere and then they will quickly learn that they better cast stuff to be safe which makes the whole thing rather pointless. And I feel pretty sorry for the Drupal folks. That list of 1000+ instances of their String class is going to suck to fix. -Rasmus

Pavel Kouřil

11 years ago
On Wed, Feb 11, 2015 at 7:36 AM, Rasmus Lerdorf <rasmus@lerdorf.com> wrote:
> On 02/10/2015 07:57 PM, Xinchen Hui wrote: >>> am I wrong?! >> seems I am wrong with this, it's a false alarm... it can restore automatically. > > Yeah, declare() doesn't span files so that isn't a problem. > > My worry is still the lack of type coercion for internal calls. I tested > it on some apps and it will take quite a bit of tedious and rather > useless effort to fix these to run in strict mode. Some examples of > common things that are fatal errors in strict mode: > > ini_set('precision', 14); > > ini_set('display_errors', 1); > > ini_set('display_errors', true); > > ok, not common, but tan(4/2) fatal, tan(5/2) no error > > Wordpress has this function, spot the error: > > function add_magic_quotes( $array ) { > foreach ( (array) $array as $k => $v ) { > if ( is_array( $v ) ) { > $array[$k] = add_magic_quotes( $v ); > } else { > $array[$k] = addslashes( $v ); > } > } > return $array; > } > > $v may not always be a string (it died with a float for me), so the > fix is to cast: > > $array[$k] = addslashes( (string)$v ); > > Also from Wordpress: > > $formatted = number_format( $number, absint( $decimals ), > $wp_locale->number_format['decimal_point'], > $wp_locale->number_format['thousands_sep'] ); > > Here number_format() is expecting a float but $number is a string. So > again, the only real fix is to cast. > > And in Drupal8 *without turning on strict*: > > use Drupal\Component\Utility\String; > > it dies with: "Fatal error: "string" cannot be used as a class name in > /var/www/drupal/core/includes/bootstrap.inc on line 11" > > That String class is everywhere in Drupal. They are going to have a > fun time with that. See > https://gist.githubusercontent.com/anonymous/d9252deeeb2aae1a5af5/raw/053155130d22551b1404d0a9b94e27424544b6d1/gistfile1 > > From Geeklog: > > if (strtolower($topic) != strtolower($archivetid)) { > $sql .= " AND ta.tid != '{$archivetid}' "; > } > > $topic can be null there. Looking at the logic, not really a bug, > just a natural reliance on null being coerced to "" > > Also from Geeklog: > > if( empty( $date )) { > // Date is empty, get current date/time > $stamp = time(); > } else if( is_numeric( $date )) { > // This is a timestamp > $stamp = $date; > } else { > // This is a string representation of a date/time > $stamp = strtotime( $date ); > } > // Format the date > $date = strftime( $dateformat, $stamp ); > > strftime() expects an integer for the timestamp there, but as the > above logic shows, they are expecting a numeric string to be fine. > No bug, just another forced cast. > > And another number_format() instance where arg1 is not necessarily > a float. Obviously not a bug, so we have to cast again: > > return number_format( $number, $dc, $ds, $ts ); > > In Opencart: > > $this->image = imagecreatetruecolor($width, $height); > imagecreatetruecolor() expects parameter 1 to be integer, string > given in /var/www/opencart/system/library/image.php on line 89 > > You could argue this is a bug, I guess, but the width and height are > coming from a database and are integers in the db, but since the db > returns strings. Another cast... > > I was genuinely hoping to find some bugs with this exercise. I suppose > it is because I did it on mature projects and at this stage those sorts > of bugs have already been fixed. But I still fear that people are going > to want to be enable strictness everywhere and then they will quickly > learn that they better cast stuff to be safe which makes the whole thing > rather pointless. And I feel pretty sorry for the Drupal folks. That > list of 1000+ instances of their String class is going to suck to fix. > > -Rasmus >
Helo, the Drupal thing seems scary. Also, I realized one thing why I think the strict version is a bad idea for PHP (in the state PHP is now - in an ideal world I would love to have nothing but strongly typed PHP, but that's offtopic) - PHP has many functions that return multiple types, so you cannot do foo(bar()) if bar() has multiple return types. :( Regards Pavel Kouril

Andrew Faulds

11 years ago
Hi Pavel,
> On 11 Feb 2015, at 07:41, Pavel Kouřil <pajousek@gmail.com> wrote: > > Also, I realized one thing why I think the strict version is a bad > idea for PHP (in the state PHP is now - in an ideal world I would love > to have nothing but strongly typed PHP, but that's offtopic) - PHP has > many functions that return multiple types, so you cannot do foo(bar()) > if bar() has multiple return types. :(
You can’t do it with weak types either. Functions with multiple return type usually do so in order to use one type for success, and another return type on failure. In weak typing mode, PHP would just mangle the error value (like FALSE).
-- Andrea Faulds http://ajf.me/

Nikita

11 years ago
On 11 Feb 2015 09:38, "Rasmus Lerdorf" <rasmus@lerdorf.com> wrote:
> > On 02/10/2015 07:57 PM, Xinchen Hui wrote: > >> am I wrong?! > > seems I am wrong with this, it's a false alarm... it can restore
automatically.
> > Yeah, declare() doesn't span files so that isn't a problem. > > My worry is still the lack of type coercion for internal calls. I tested > it on some apps and it will take quite a bit of tedious and rather > useless effort to fix these to run in strict mode. Some examples of > common things that are fatal errors in strict mode: > > ini_set('precision', 14); > > ini_set('display_errors', 1); > > ini_set('display_errors', true); > > ok, not common, but tan(4/2) fatal, tan(5/2) no error > > Wordpress has this function, spot the error: > > function add_magic_quotes( $array ) { > foreach ( (array) $array as $k => $v ) { > if ( is_array( $v ) ) { > $array[$k] = add_magic_quotes( $v ); > } else { > $array[$k] = addslashes( $v ); > } > } > return $array; > } > > $v may not always be a string (it died with a float for me), so the > fix is to cast: > > $array[$k] = addslashes( (string)$v ); > > Also from Wordpress: > > $formatted = number_format( $number, absint( $decimals ), > $wp_locale->number_format['decimal_point'], > $wp_locale->number_format['thousands_sep'] ); > > Here number_format() is expecting a float but $number is a string. So > again, the only real fix is to cast. > > And in Drupal8 *without turning on strict*: > > use Drupal\Component\Utility\String; > > it dies with: "Fatal error: "string" cannot be used as a class name in > /var/www/drupal/core/includes/bootstrap.inc on line 11" > > That String class is everywhere in Drupal. They are going to have a > fun time with that. See >
https://gist.githubusercontent.com/anonymous/d9252deeeb2aae1a5af5/raw/053155130d22551b1404d0a9b94e27424544b6d1/gistfile1
> > From Geeklog: > > if (strtolower($topic) != strtolower($archivetid)) { > $sql .= " AND ta.tid != '{$archivetid}' "; > } > > $topic can be null there. Looking at the logic, not really a bug, > just a natural reliance on null being coerced to "" > > Also from Geeklog: > > if( empty( $date )) { > // Date is empty, get current date/time > $stamp = time(); > } else if( is_numeric( $date )) { > // This is a timestamp > $stamp = $date; > } else { > // This is a string representation of a date/time > $stamp = strtotime( $date ); > } > // Format the date > $date = strftime( $dateformat, $stamp ); > > strftime() expects an integer for the timestamp there, but as the > above logic shows, they are expecting a numeric string to be fine. > No bug, just another forced cast. > > And another number_format() instance where arg1 is not necessarily > a float. Obviously not a bug, so we have to cast again: > > return number_format( $number, $dc, $ds, $ts ); > > In Opencart: > > $this->image = imagecreatetruecolor($width, $height); > imagecreatetruecolor() expects parameter 1 to be integer, string > given in /var/www/opencart/system/library/image.php on line 89 > > You could argue this is a bug, I guess, but the width and height are > coming from a database and are integers in the db, but since the db > returns strings. Another cast... > > I was genuinely hoping to find some bugs with this exercise. I suppose > it is because I did it on mature projects and at this stage those sorts > of bugs have already been fixed. But I still fear that people are going > to want to be enable strictness everywhere and then they will quickly > learn that they better cast stuff to be safe which makes the whole thing > rather pointless. And I feel pretty sorry for the Drupal folks. That > list of 1000+ instances of their String class is going to suck to fix. > > -Rasmus >
Hi, I believe all these projects wouldn't even want to enable strict types due to the nature of their codebase and they probably don't need to, for sure this feature is not for them... What about Drupal, if they don't use dynamic instantiation for string utility class then it can be fixed in most of IDEs out there with their "rename class" feature. Plus keywords reservation is a matter of another vote (the last one in the RFC) that can succeed even if type hints don't pass.

Andrew Faulds

11 years ago
Hi Rasmus,
> On 11 Feb 2015, at 06:36, Rasmus Lerdorf <rasmus@lerdorf.com> wrote: > > And in Drupal8 *without turning on strict*: > > use Drupal\Component\Utility\String; > > it dies with: "Fatal error: "string" cannot be used as a class name in > /var/www/drupal/core/includes/bootstrap.inc on line 11" > > That String class is everywhere in Drupal. They are going to have a > fun time with that. See > https://gist.githubusercontent.com/anonymous/d9252deeeb2aae1a5af5/raw/053155130d22551b1404d0a9b94e27424544b6d1/gistfile1
Such classes will unfortunately have to be renamed. However, this is only true if the code needs to run on PHP 7. For PHP 5 codebase compatibility, Drupal can do this: class StringHelper { … } if (version_compare(phpversion(), “7.0") < 0) { class_alias(“Drupal\\Component\\Utility\\StringHelper”, “Drupal\\Component\\Utility\\String”); } This way, only code made “PHP 7-ready" will have to replace its references to String with, say, StringHelper. Drupal can work on both PHP 5 and PHP 7, but codebases using it can migrate at their own pace.
-- Andrea Faulds http://ajf.me/

Rowan Collins

11 years ago
On 11 February 2015 06:36:52 GMT, Rasmus Lerdorf <rasmus@lerdorf.com> wrote:
> And in Drupal8 *without turning on strict*: > > use Drupal\Component\Utility\String; > > it dies with: "Fatal error: "string" cannot be used as a class name in >/var/www/drupal/core/includes/bootstrap.inc on line 11" > > That String class is everywhere in Drupal. They are going to have a > fun time with that. See >https://gist.githubusercontent.com/anonymous/d9252deeeb2aae1a5af5/raw/053155130d22551b1404d0a9b94e27424544b6d1/gistfile1
That could potentially be avoided if scalar types were reserved as some kind of pseudo-class rather than just keywords, because then they would follow namespace resolution rules. Theoretically, you could still have a class "Drupal\Component\Utility\String", and "\string" would be available as a scalar typehint while you were in that namespace. I'm guessing it's not as simple as that, because the compiler needs to distinguish between scalar and classname typehints, but doesn't know what classes exist. In which case, perhaps "string" as a typehint could always mean "\string", and if you want to typehint the class you should always use "foo\string"? Or you could ban "string" as a typehint, and require people to type "\string". Either seems a little bit magic, though. Theoretically, I guess they ought to be "php\string" etc, which would accomplish the goal but make them rather unwieldy. It might be worth considering, though, given we know the situation's not just hypothetical. Regards,
-- Rowan Collins [IMSoP]

Zeev Suraski

11 years ago
> -----Original Message----- > From: Rasmus Lerdorf [mailto:rasmus@lerdorf.com] > Sent: Wednesday, February 11, 2015 8:37 AM > To: Xinchen Hui; Andrea Faulds > Cc: PHP Internals > Subject: Re: [PHP-DEV] [VOTE] Scalar Type Hints > > On 02/10/2015 07:57 PM, Xinchen Hui wrote: > >> am I wrong?! > > seems I am wrong with this, it's a false alarm... it can restore > automatically. > > Yeah, declare() doesn't span files so that isn't a problem. > > My worry is still the lack of type coercion for internal calls.
There's also some pretty interesting analysis on this proposal - based on some real world experimentation - from Benjamin Eberlei - bit.ly/1vl0UED If you've voted on this RFC or intend to vote - please spend the few minutes to read through his blog post. It does a good job at actually illustrating what life would look like if this rubber ends up meeting the road. Zeev

Andrew Faulds

11 years ago
> On 11 Feb 2015, at 21:30, Zeev Suraski <zeev@zend.com> wrote: > >> -----Original Message----- >> From: Rasmus Lerdorf [mailto:rasmus@lerdorf.com] >> Sent: Wednesday, February 11, 2015 8:37 AM >> To: Xinchen Hui; Andrea Faulds >> Cc: PHP Internals >> Subject: Re: [PHP-DEV] [VOTE] Scalar Type Hints >> >> On 02/10/2015 07:57 PM, Xinchen Hui wrote: >>>> am I wrong?! >>> seems I am wrong with this, it's a false alarm... it can restore >> automatically. >> >> Yeah, declare() doesn't span files so that isn't a problem. >> >> My worry is still the lack of type coercion for internal calls. > > There's also some pretty interesting analysis on this proposal - based on > some real world experimentation - from Benjamin Eberlei - bit.ly/1vl0UED
I disagree with some aspects of the blogpost:
> enabling strict mode completly defeats the purpose, because now we are forced to convert manually, reimplementing weak type hinting in our own code
This isn’t true at all. The key difference between explicit conversions and implicit conversions is that they’re, well, *explicit*. You can see them, they are blatantly obvious, if you use grep you can find them. Implicit conversions, while they can sometimes be great, happen silently and automatically - if they screw up, it can be hard to track down where the conversion is taking place. With explicit conversions, you’re converting once and you know you’ve converted. With implicit conversions, you have no idea where and how often values are being converted.
> We write code with casts already, the scalar type hints patch is not necessary for that! Only a superficial level of additional safety is gained, one additional check of something we already know is true!
Yet in the previous part he was explaining how existing code doesn’t use casts and would need them added… so therefore, this thing *isn’t* already known to be true, and the blogpost is self-contradictory.
> strict mode is useless for library developers, because I always have to assume weak mode anyways.
I don’t really understand at all… either he doesn’t understand the proposal (which guarantees you get the types you ask for), or it’s a reference to the claim from the previous paragraph, which I’ve already responded to.
> In a well designed application or library, the developer can already trust the types of his variables today, 95% of the time, without even having type hints, using carefully designed abstractions (example Symfony Forms and Doctrine ORM): No substantial win for her from having strict type hints.
Yet he was previously explaining how, actually, data coming in from web requests isn’t the correct types.
> In a badly designed application, the developer is uncertain about the types of variables. Using strict mode in this scenario she needs to start casting everywhere just to be sure.
In an application using strict mode everywhere with scalar type hints everywhere, you can’t possibly be uncertain about the types of variables. … there’s a lot more in that blog post I could disagree with, but I won’t bother. Benjamin has his reasons for not liking strict mode. That’s fine. But if PHP adds strict mode, it has zero effect on him.
> If you've voted on this RFC or intend to vote - please spend the few minutes > to read through his blog post. It does a good job at actually illustrating > what life would look like if this rubber ends up meeting the road.
Anthony Ferrara also had his own analysis which showed some of the problems with weak type hinting, and where strict types can be beneficial: http://blog.ircmaxell.com/2015/02/scalar-types-and-php.html I would suggest people read that blog post before voting, as well. It points out some real-world examples of where weak typing in PHP can be insufficient (div), or even downright dangerous (curlopt).
-- Andrea Faulds http://ajf.me/

Lester Caine

11 years ago
On 11/02/15 21:46, Andrea Faulds wrote:
> Anthony Ferrara also had his own analysis which showed some of the problems with weak type hinting, and where strict types can be beneficial: http://blog.ircmaxell.com/2015/02/scalar-types-and-php.html
What is the point of using a 'Better static analyzer' when the bulk of the material being worked with simply can't be processed 'statically'? The only result of this passing that I can see is that PHP will start to develop two completely different code bases. Anthony closes by saying that is EXACTLY what he will do ...
-- 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

Rowan Collins

11 years ago
On 11 February 2015 22:41:21 GMT, Lester Caine <lester@lsces.co.uk> wrote:
>On 11/02/15 21:46, Andrea Faulds wrote: >> Anthony Ferrara also had his own analysis which showed some of the >problems with weak type hinting, and where strict types can be >beneficial: http://blog.ircmaxell.com/2015/02/scalar-types-and-php.html > >What is the point of using a 'Better static analyzer' when the bulk of >the material being worked with simply can't be processed 'statically'? >The only result of this passing that I can see is that PHP will start >to >develop two completely different code bases. Anthony closes by saying >that is EXACTLY what he will do ...
No, he closes by saying he will use the feature differently in different parts of one code base. Indeed, he makes a specific point about the advantage of having a weakly typed file and a strictly typed file working together.

Benjamin Eberlei

11 years ago
On Wed, Feb 11, 2015 at 10:46 PM, Andrea Faulds <ajf@ajf.me> wrote:
> > > On 11 Feb 2015, at 21:30, Zeev Suraski <zeev@zend.com> wrote: > > > >> -----Original Message----- > >> From: Rasmus Lerdorf [mailto:rasmus@lerdorf.com] > >> Sent: Wednesday, February 11, 2015 8:37 AM > >> To: Xinchen Hui; Andrea Faulds > >> Cc: PHP Internals > >> Subject: Re: [PHP-DEV] [VOTE] Scalar Type Hints > >> > >> On 02/10/2015 07:57 PM, Xinchen Hui wrote: > >>>> am I wrong?! > >>> seems I am wrong with this, it's a false alarm... it can restore > >> automatically. > >> > >> Yeah, declare() doesn't span files so that isn't a problem. > >> > >> My worry is still the lack of type coercion for internal calls. > > > > There's also some pretty interesting analysis on this proposal - based on > > some real world experimentation - from Benjamin Eberlei > > I disagree with some aspects of the blogpost: > > > enabling strict mode completly defeats the purpose, because now we are > forced to convert manually, reimplementing weak type hinting in our own code > > This isn’t true at all. The key difference between explicit conversions > and implicit conversions is that they’re, well, *explicit*. You can see > them, they are blatantly obvious, if you use grep you can find them. > Implicit conversions, while they can sometimes be great, happen silently > and automatically - if they screw up, it can be hard to track down where > the conversion is taking place. With explicit conversions, you’re > converting once and you know you’ve converted. With implicit conversions, > you have no idea where and how often values are being converted. > > > We write code with casts already, the scalar type hints patch is not > necessary for that! Only a superficial level of additional safety is > gained, one additional check of something we already know is true! > > Yet in the previous part he was explaining how existing code doesn’t use > casts and would need them added… so therefore, this thing *isn’t* already > known to be true, and the blogpost is self-contradictory. > > > strict mode is useless for library developers, because I always have to > assume weak mode anyways. > > I don’t really understand at all… either he doesn’t understand the > proposal (which guarantees you get the types you ask for), or it’s a > reference to the claim from the previous paragraph, which I’ve already > responded to. > > > In a well designed application or library, the developer can already > trust the types of his variables today, 95% of the time, without even > having type hints, using carefully designed abstractions (example Symfony > Forms and Doctrine ORM): No substantial win for her from having strict type > hints. > > Yet he was previously explaining how, actually, data coming in from web > requests isn’t the correct types. > > > In a badly designed application, the developer is uncertain about the > types of variables. Using strict mode in this scenario she needs to start > casting everywhere just to be sure. > > In an application using strict mode everywhere with scalar type hints > everywhere, you can’t possibly be uncertain about the types of variables. > > … there’s a lot more in that blog post I could disagree with, but I won’t > bother. Benjamin has his reasons for not liking strict mode. That’s fine. > But if PHP adds strict mode, it has zero effect on him. >
Wait i almost forgot, it *does* have an effect on me, especially around callback handling: https://gist.github.com/schmittjoh/778e044deacc6f1fe516 Essentially callbacks are evaluated in the mode they are called in, not in the one they are defined.

Matteo Beccati

11 years ago
On 13/02/2015 17:29, Benjamin Eberlei wrote:
> Wait i almost forgot, it *does* have an effect on me, especially around > callback handling: > > https://gist.github.com/schmittjoh/778e044deacc6f1fe516 > > Essentially callbacks are evaluated in the mode they are called in, not in > the one they are defined.
This is indeed interesting. And the failure could even be not so obvious like a mismatch between the callback signature and what the caller expects. Cheers
-- Matteo Beccati Development & Consulting - http://www.beccati.com/

Matteo Beccati

11 years ago
On 13/02/2015 17:58, Matteo Beccati wrote:
> On 13/02/2015 17:29, Benjamin Eberlei wrote: >> Wait i almost forgot, it *does* have an effect on me, especially around >> callback handling: >> >> https://gist.github.com/schmittjoh/778e044deacc6f1fe516 >> >> Essentially callbacks are evaluated in the mode they are called in, >> not in >> the one they are defined. > > This is indeed interesting. > > And the failure could even be not so obvious like a mismatch between the > callback signature and what the caller expects.
Actually I was mistaken, as in fact the closure body would run in weak-mode. A bit confusing indeed, though ;) Cheers
-- Matteo Beccati Development & Consulting - http://www.beccati.com/

Nikita

11 years ago
On 13 Feb 2015 19:37, "Benjamin Eberlei" <kontakt@beberlei.de> wrote:
> > Wait i almost forgot, it *does* have an effect on me, especially around > callback handling: > > https://gist.github.com/schmittjoh/778e044deacc6f1fe516 > > Essentially callbacks are evaluated in the mode they are called in, not in > the one they are defined. >
You're presenting it like this is a wrong behavior whereas it's expectable to work like this. One thing php will definitely lack especially after/if this RFC gets accepted is callback signature type hints, but maybe we'll see them in 7.x

Grégory Planchat

11 years ago
Le 05/02/2015 21:14, Andrea Faulds a écrit :
> Good evening, > > At long last, I’m going to put the RFC to a vote. It’s been long enough - I don’t think there needs to be, or will be, much further discussion. > > I’d like to make sure that everyone voting understands the RFC fully. Please read the RFC in full: the details are important. And if anyone has any questions or uncertainties, please ask them before voting. I am very happy to answer them. > > I would urge everyone who wants type hints to vote for this RFC. It is not a perfect solution, but there can be no perfect solution to this issue. However, I think it is better than most of the alternatives suggested thus far - see the rationale section, and previous discussions. Crucially, this RFC would keep PHP a weakly-typed language, and not force either strict typing, nor weak typing, on anyone who does not want it. It would allow the addition of type hints to existing codebases. It would not create a situation where userland functions are strict yet internal functions are not, because the strict mode affects both. I’ve tested the implementation myself on my own code, and it worked well, providing benefits other proposals would not have given (see my previous post about my experiences). > > Voting starts today (2015-02-05) and ends in two weeks’ time (2015-02-19). In addition to the vote on the main RFC, there is also a vote on the type aliases issue, and a vote to reserve the type names for future RFCs’ sake if this RFC fails. > > The RFC can be found here, and it contains a voting widget: https://wiki.php.net/rfc/scalar_type_hints > > Thank you for your time. > > -- > Andrea Faulds > http://ajf.me/ > > > >
Hi, I vote for the scalar type hints in PHP7, with the synonyms throwing error messages (and reserve the names if the RFC does not pass) Grégory Planchat

Pascal MARTIN

11 years ago
Le 05/02/2015 21:14, Andrea Faulds a écrit :
> Voting starts today (2015-02-05) and ends in two weeks’ time (2015-02-19). In addition to the vote on the main RFC, there is also a vote on the type aliases issue, and a vote to reserve the type names for future RFCs’ sake if this RFC fails. > > The RFC can be found here, and it contains a voting widget: https://wiki.php.net/rfc/scalar_type_hints >
Hi, Even if this RFC has been withdrawn, I'm posting this here, hoping it might prove useful if someone ever tries to revive it. We've discussed this RFC quite a bit with other members of AFUP, and finally ended on the +1 side. Basically, adding type-hinting for scalars goes towards a PHP that is a bit more "strict" -- which seems like a good thing for us. But, at the same time, the "weak" mode by default means users can choose to go that way at their own pace and existing code will keep working, even if calling "strict" libraries. The biggest concern we've had is the declare() syntax that feels a bit weird at first. But that's not enough of a concern for us to be -1 on the RFC as a whole. Thanks!
-- Pascal MARTIN, AFUP - French UG http://php-internals.afup.org/

netroby

11 years ago
We do not have Scalar type hints for years. we code in php for years without any type check. it's ok. not the primary things. Look at other dynamic programming language, they may not have the type check either. It is ok, and it is fine. Besides php, there be always other choice. If you really really need type check now. Take a look HHVM. I guest hacklang will match your need. If the PHP keep current states, my code will running till the earth dead. It works like a ancient rock. What ever , i just care my code work or not. Appreciate your time. ---------------------------- Netroby 2015-02-16 15:30 GMT+08:00 Pascal MARTIN, AFUP <mailing@pascal-martin.fr>:

François Laupretre

11 years ago
> De : Netroby [mailto:hufeng1987@gmail.com] > > We do not have Scalar type hints for years. we code in php for years > without any type check. it's ok. not the primary things. > > Look at other dynamic programming language, they may not have the type > check either. > > It is ok, and it is fine. > > Besides php, there be always other choice. > > If you really really need type check now. Take a look HHVM. > > I guest hacklang will match your need. > > If the PHP keep current states, my code will running till the earth dead. > It works like a ancient rock. What ever , i just care my code work or not. > Appreciate your time.
Do you understand that such condescending and non-constructive attitude pushed Andrea to leave, like many others before her ? but I guess you don't care and won't change your attitude. Really sad. François