Yii Framework Forum

Strict types for Yii 3

(Pawel) #1

Is there a reason not to use declare(strict_types=1); for Yii 3 other than “that’s a lot of types adding”? :wink:

I can see that neither Symfony nor Laravel are using strict typing as well.


The main reason is that it does not give you much benefit for mature and battle-tested software, and enabling strict types blindly will just break stuff. So your question is fundamentally wrong - you should ask “why (and where) we should use strict types?” instead of “why we should not use strict types?” :smiley:

(Alexander Makarov) #3

We can benefit from more type-hints and these are already used for some classes.

declare(strict_types=1); makes sense for many classes but certainly not controllers where everything inputted is a string.


The same is true for PDO, which also returns string values in most cases, so when working with these strict typing makes things harder.

(Lubosdz) #5

Strict mode is not widely used in applications. So for most of users this would become a blocker because they would need to follow strict types also in their apps, if framework would follow strict types. There are also some critical unsolved situations about strict types like PDO (mysql) returning numeric strings even for integer columns.


Strict mode in framework core classes should not have any effect on applications created using Yii (at least if we do it right).

(Serban Cristian) #7

This has to be a must, not something optional. strict types together with type hinting.
I was hoping all core classes will use type hinting…