Skip to content

Conversation

@kenjis
Copy link
Member

@kenjis kenjis commented Aug 15, 2022

  • add declare_strict_types rule to php-cs-fixer
  • add declare(strict_types=1)

@kenjis kenjis added the refactor Pull requests that refactor code label Aug 15, 2022
Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to see everything was already working as strict! I think this is a good change. @lonnieezell has been hesitant in the past so let's make sure he has a chance to weigh in.

@paulbalandan
Copy link
Member

When will this ship to the main repo?? 🤔😂

@lonnieezell
Copy link
Member

If everyone else on the team feels strongly then we should do this then do it. My hesitation has always been based on an incorrect understanding I think. IIRC, this will still cast numeric strings, for example, into ints when called from my code, just not when called within the same file. If I'm remembering that correct then I'm fine. If I'm not, and it forces you to explicitly cast in your own code I find that onerous. I stopped programming in C/C++ years ago and don't have an interest in using Java :)

@kenjis
Copy link
Member Author

kenjis commented Aug 15, 2022

See https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.strict

Strict typing applies to function calls made from within the file with strict typing enabled, not to the functions declared within that file. If a file without strict typing enabled makes a call to a function that was defined in a file with strict typing, the caller's preference (coercive typing) will be respected, and the value will be coerced.

@datamweb
Copy link
Collaborator

There is one thing that you need to keep in mind when using the strict_type declaration. It only works for the file that the declaration is placed in. Meaning that when you use a class, which has the strict_type declaration, it can still result in PHP casting primitive value. So keep that in mind when you want to start using this!

@lonnieezell
Copy link
Member

Perfect. Then I'm fine.

@kenjis kenjis merged commit 1f0e8b4 into codeigniter4:develop Aug 15, 2022
@kenjis kenjis deleted the add-strict_types branch August 15, 2022 20:19
@MGatner
Copy link
Member

MGatner commented Aug 16, 2022

Yes, these are correct. The good news is that declaring strict has grown massively during the static analysis era, since most SA tools actually end up enforcing proper "strict" handling already. I expect a larger percent of developers than ever to understand the benefits and limitations.

Merge complete. On to the main repo! ====€

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Pull requests that refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants