Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Type Hinting #284

Open
Azareal opened this issue Feb 20, 2017 · 4 comments
Open

Type Hinting #284

Azareal opened this issue Feb 20, 2017 · 4 comments

Comments

@Azareal
Copy link
Contributor

Azareal commented Feb 20, 2017

Type Hinting was one of the big features which landed in PHP7, I'm assuming you already have an idea as to what it is, but in short you can mark methods, functions, etc. up with little type hints as to what it will expect and the language will scream when you violate those constraints.

It should help to find cases where strange inputs are passed to a method / function, usually the sign of a bug. And it helps methods / functions to be self-documenting. I briefly mentioned it on Discord to @euantorano and he seemed supportive of the idea.

I'm working on a pull request for this. Type hinting is actually already used in MyBB2, albeit rarely.
My upcoming pull request will help to greatly expand the coverage. #286

@ghost
Copy link

ghost commented Jun 4, 2017

Type Hinting was already in PHP5, just with PHP7 you can now hint scalar types and declare return types.

@Azareal
Copy link
Contributor Author

Azareal commented Jun 4, 2017

I know, but type-hints are practically useless before PHP7.

@ghost
Copy link

ghost commented Jun 4, 2017

Maybe you've never type-hint callables or classes, but others have (like me) and that's a) useful and b) usable in PHP5.

@Azareal
Copy link
Contributor Author

Azareal commented Jun 5, 2017

Considering that it's missing the most useful features, and it's barely usable, I could barely call that support. How many bugs are really going to be prevented with a few callables or classes? Perhaps, they might work for perfectionism's sake, but they're not that useful in practice.

With scalar type-hints, there are hundreds upon hundreds of bugs which will be caught and eradicated before they cause any damage in a gold release. I know this from experience, as many of the bugs I've dealt with in PHP involve scalars doing stupid things at stupid times. It's not perfect, but it's a big step forward.

Locking the type of a variable to stop it accidentally mutating would be another good step for PHP, but it's unknown when they'll do that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant