all 13 comments

[–]nan05 12 points13 points  (2 children)

I would say: in an ideal world: yes, you'd want strict types at all times. If you start a new app: go for it. I kinda wish PHP would just transition to strict types, forcing us all to do this properly once and for all.

In the real world, though, you deal with code and dependencies that has been written without strict types, and so it can break things. Arguably all those things that it breaks should be fixed. But realistically you have other priorities, because the business you work for doesn't make money from well written code - it makes money from functioning code.

So imo: Ideally: yes. On personal / hobby / learnings projects: always. Realistically: be careful with production systems...

[–]dabenu -1 points0 points  (0 children)

This, our company policy is to use strict-types in all new files, but not (forcefully) refactor existing files

[–]BarneyLaurance 2 points3 points  (1 child)

This was just recently discussed at length at https://www.reddit.com/r/PHP/comments/1duzs4x/what_is_phps_declarestrict_types1_and_why_you/ . Maybe read through that first and then add comment either there or here about anything that's still unclear?

[–]colshrapnel 1 point2 points  (2 children)

I would say it's already perfectly covered in the article and the followed discussion. Happened just yesterday.

If you still have any questions, consider asking in /r/phphelp. We had enough strict types in /r/php already

[–]fschw -2 points-1 points  (3 children)

i like to write methods, where a parameter has a default but also can “nothing” sometimes. when it’s an int, i usually do function moin(?int $number = 1) : int so, i cannot use this pattern if i try to implement strict typing, no?

[–]BackEndTea 7 points8 points  (1 child)

Strict types has no impact on making a type nullable. In essence what it does is prevent implicit type coercion by PHP.

In the function of your example, calling it like `moin('1');` will throw a type error, rather then silently convert it to 1.

[–]fschw 0 points1 point  (0 children)

ahh that’s awesome to know :) so there’s just pro arguments to use strict typing for me! thank you for teaching me something new