PSR-1 2.3 Side Effects Rule

99封情书 提交于 2019-12-04 00:03:29

The idea is that when a class is auto-loaded, the state of the application should not change. Any state-modifying code (code that actually executes) should be in a different set of files.

This makes it predictable and forces you to keep your logic in class methods, and implicit.

Remember that coding standards exist so people code in a similar style. The benefit in adopting a coding standard is that your codebase is self-consistent and consistent with other projects following the rules.

PSR-1 largely follows what everybody was already doing. If you feel the need to execute logic in the same place where a class is defined, there is very likely a better place or approach.

Lastly.. don't adopt PSR-1 for the sake of. If you have a valid reason to not follow the rules in certain spots, break the rules. They're not laws. Common sense reigns supreme.

Source: I'm one of the contributers of that document.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!