Replies: 1 comment 2 replies
-
Strict typing impacts function calls, not function definitions, so it would primarily impact first party code. This is because WordPress function definitions do not use type hints, so declaring strict types would have no impact if passing ostensibly incorrect parameter types to core functions. Both scenarios should be adequately accounted for by correctly implementing static analysis via PHPStan, since WP code does specify acceptable parameter types in its DocBlocks. With strict typing enabled, PHP will throw a Fatal TypeError when incorrect parameter types are passed. This is fine during development, but — in my opinion — we would normally prefer to quietly error, rather than terminate execution (in production). It is very possible to break the application completely if all edge cases are not accounted for when handling user data. Further to this, Fatal Error stack traces have the potential to expose sensitive data if the The Generic standard in PHPCS itself includes a sniff that can enforce the declaration, so we wouldn't necessarily need to write a custom sniff for this:
Nitpick - our coding standards would require the declaration to look like this: <?php
declare( strict_types = 1 ); |
Beta Was this translation helpful? Give feedback.
-
Hey all.
I'm looking to get a consensus on where people's preferences lie regarding declaring strict types in PHP files, ie:
Is this something we're doing across most projects in Big Bite? If not, should we be? Should we consider adding a sniff to help enforce/guide inclusion of this declaration?
On the other hand, if we're not in a position to add this to our shared PHPCS config, is anyone aware of an existing sniff that could be used at project level should we want to enforce this?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions