Scalar Type Hints - Yay or Nay?

This is today’s newsletter editorial discussion, copied here for the sake of easier discussion

Andrea Faulds, a contributor to the core of the PHP language, recently suggested a new RFC that would, if accepted, add scalar type hints to PHP 7 in the form of Hack.

The scalar type hints would remain optional, with a strict mode available for those who desire it, and it has been explained in detail quite well by Pascal Martin - a post you should definitely read.

What resonated more through the PHP community, however, was the rift prompted by the vote for this feature. With alarming accuracy, most of the old guard of the PHP internals team (the ones responsible for the language’s first iterations) have voted “No”, some stating that PHP has always been a weakly typed language and should remain one, and others blatantly misunderstanding what the RFC proposes to accomplish. On the other cliff of the rift, however, the views seemed similarly extremist at times.

Naturally, there were those who logically argued for either approach and those discussions should be taken into account when deciding on the vote, but the amount of hostile bickering surprised and frightened me - a divide between the two core contributor groups of an entire programming language is hardly what I would call a productive environment for anyone, and I fear stagnation as all future votes stand deadlocked in personal bias.

Personally, I want to see this happen. I wasn’t around in PHP’s <5 days, so upgrading the language with such optional perks is definitely the way to go from where I’m looking. I can understand the hesitance of the original devs and quite frankly, we already do have Hack to give us the “new PHP” we all wanted, but this would add not only a more professional (optional) layer on top of our favorite language, it would also foster compatibility with the rapidly evolving Hack.

How do you feel about scalar type hints? (please read the RFC and Pascal’s post to get a full picture before answering)

I support this, I read a blogpost by Anthony Ferrara who implied that the passing of this RFC will open A LOT OF doors, which I totally agree. I’d like to see Nikita Popov’s scalar objects idea passing through too, and scalar type hinting will be one step necessary to achieve true strong/safe typing in PHP.

1 Like


For reference: Anthony’s post and matching reddit discussion.

Do you have a link to that? I’d love to read it.

I’ll be honest. One of the reasons I don’t use PHP often any more is the lack of type hinting. Yes, you can do it to some extent, but I want to do it everywhere. Why? Because it makes it easier for me to read and switch between the languages that require it.

It takes a level of validation out of the mix, which is awesome!, and it catches problems of people implementing the given task/method wrong quicker.

Maybe it is because I started in C and C# and VB.NET where type was required and eventually those language went backwards and permit var address = new Address(); but you can sort of permit this because the right side easily defines the type. PHP that isn’t always the case var number = "1";

'Tis here.

Indeed. I like strict structure, too.

Oh I was about to post the link, you beat me to it. But thanks. I think after scalar type hinting RFC passes(hopefully), we should start a campaign to get scalar object into PHP 7 core. I hope Nikita Popov will bring it to RFC soon, and I wish there would be little to no objection of it passing when it goes to voting phase.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.